Hi,
I've gotten a bit more advanced since I last posted... I've been learning Xbasic and Xdialogs and seem to have gotten past the steep part of the learning curve. But remember that I am a beginner and could easily have made a beginner's mistake.
The attached script is a heavy modification of the ActionScript Progressive Search. For the purpose of posting it here I've changed it to work with ActionSports (which was easy), so you can plop it in there and run it. It's not finished... I've been working on the listing of names and have gotten stuck on the sort that occurs when you select a column heading. I haven't worked much on the buttons, selection, or return value. There's a little bit of trace output (via UI_MSG_BOX) that you can ignore.
Two things are wrong. First, there is an <array>.SORT() call in the cDoSort function that does nothing. I've traced the input to it and everything looks ok. It just won't sort. Next, I wrote a function to dump the contents of an array of property variables, which is what the sort works with, and which I wrote mostly to help debug the sort problem. I used the ENUM_PROPERTIES() function, which also seems to do nothing.
Common sense says the two problems are related, and I've either made some dumb error and/or there's something wrong with the property array in question. But the array is used successfully elsewhere, and if I look at it with the debugger it has the right stuff in it. My conclusion is that there's something wrong with Alpha, but I'm experienced enough to know that that's probably not the case. I'm hoping that some experienced eyes can see what I've missed. (It'll also be a nice progressive search (for small tables) when it's done...).
It's a pretty big script but the code in question is near the top of the file, so you don't have to look very far to see what's not working.
Here's the code (I've also attached it as a txt file...):
[I hope I formatted that right...]
I don't expect anyone to go over the whole thing, but I'm open to any suggestions for improving the code.
Thanks for looking!
-jimc
I've gotten a bit more advanced since I last posted... I've been learning Xbasic and Xdialogs and seem to have gotten past the steep part of the learning curve. But remember that I am a beginner and could easily have made a beginner's mistake.
The attached script is a heavy modification of the ActionScript Progressive Search. For the purpose of posting it here I've changed it to work with ActionSports (which was easy), so you can plop it in there and run it. It's not finished... I've been working on the listing of names and have gotten stuck on the sort that occurs when you select a column heading. I haven't worked much on the buttons, selection, or return value. There's a little bit of trace output (via UI_MSG_BOX) that you can ignore.
Two things are wrong. First, there is an <array>.SORT() call in the cDoSort function that does nothing. I've traced the input to it and everything looks ok. It just won't sort. Next, I wrote a function to dump the contents of an array of property variables, which is what the sort works with, and which I wrote mostly to help debug the sort problem. I used the ENUM_PROPERTIES() function, which also seems to do nothing.
Common sense says the two problems are related, and I've either made some dumb error and/or there's something wrong with the property array in question. But the array is used successfully elsewhere, and if I look at it with the debugger it has the right stuff in it. My conclusion is that there's something wrong with Alpha, but I'm experienced enough to know that that's probably not the case. I'm hoping that some experienced eyes can see what I've missed. (It'll also be a nice progressive search (for small tables) when it's done...).
It's a pretty big script but the code in question is near the top of the file, so you don't have to look very far to see what's not working.
Here's the code (I've also attached it as a txt file...):
Code:
'Date Created: 02-Aug-2013 11:59:38 PM 'Last Updated: 03-Aug-2013 01:08:06 AM 'Created By : Jim 'Updated By : Jim 'Inline-Xbasic. Converted from: Create an Xdialog Progressive Search. DIM SHARED vLastname as C DIM SHARED varC_result as C DIM SHARED vListview AS C DIM cFuncSrc AS C = <<%code% FUNCTION cDumpPropArray AS C(aArray AS P) DIM cResult AS C = "" FOR EACH x IN aArray cResult = cResult+CRLF() cResult = PROPERTIES_ENUM(x,"R;O=p|v|t") NEXT cDumpPropArray = cResult END FUNCTION FUNCTION cDoSort AS C(BYREF CurSrtFld AS C,\ BYREF CurSrtDir AS C,NewSrtFld AS C,\ pTableDef AS P,aContents AS P) IF NewSrtFld=CurSrtFld CurSrtDir = IIF(CurSrtDir="D","AB","D") ELSE CurSrtFld = NewSrtFld CurSrtDir = "AB" END IF UI_MSG_BOX("cDoSort","CurSrtFld="+CurSrtFld+CRLF()+"CurSrtDir="+CurSrtDir) UI_MSG_BOX("cDoSort","aContents 1: "+cDumpPropArray(aContents)) 'aContents.SORT(CurSrtDir,STRITRAN(CurSrtFld,"->","__")) aContents.SORT(CurSrtDir,CurSrtFld) UI_MSG_BOX("cDoSort","aContents 2: "+cDumpPropArray(aContents)) cDoSort = cDumpContents(pTableDef,aContents) UI_MSG_BOX("cDoSort","RETURN: "+cDoSort) END FUNCTION FUNCTION cGetContents AS C(pTableDef AS P,aContents AS P,pContext AS P) DIM cFieldList AS C DIM cContentExp AS C DIM pTable AS P DIM cFilter AS C aContents.CLEAR() IF .NOT.FILE.EXISTS(TABLE.FILENAME_GET(pTableDef.TableName)) UI_MSG_BOX("ProgressiveLookup:cGetContents","Table missing:"+ \ TABLE.FILENAME_GET(pTableDef.TableName)) EXIT FUNCTION END IF pTable = TABLE.OPEN(pTableDef.TableName,FILE_RO_SHARED) aContents.RESIZE(pTable.RECORDS_GET()) pTable.CLOSE() cFilter = pTableDef.Filter cFilter = cGetArgs(pTableDef,pContext) cFilter = CONVERT_EXPRESSION(cFilter,"VC","",pContext) aContents.INITIALIZE_FROM_TABLE(pTableDef.TableName,cFilter,pTableDef.Order) cGetContents = cDumpContents(pTableDef,aContents) END FUNCTION FUNCTION cDumpContents AS C(pTableDef AS P,aContents AS P) DIM cEval AS C pTableDef.FieldList = ALLTRIM(pTableDef.FieldList) IF pTableDef.FieldList="" cDumpContents = "No Fields" EXIT FUNCTION END IF cEval = *FOR_EACH(x,"TrimCRLFs(x."+ \ STRITRAN(TABLE.NAME_NORMALIZE(x),"->","__")+")", \ pTableDef.FieldList) cEval = ALLTRIM(cEval) cEval = STRITRAN(cEval,CRLF(),"+"+QUOTE("|")+"+") IF pTableDef.cRetValExp <> "" cEval = QUOTE("{DATA=")+"+TrimCRLFs(x."+ \ STRITRAN(TABLE.NAME_NORMALIZE(pTableDef.cRetValExp), \ "->","__")+")+"+QUOTE("}")+"+"+cEval END IF cEval = "*FOR_EACH(x,"+cEval+",aContents)" cDumpContents = EVAL(cEval) END FUNCTION FUNCTION TrimCRLFs AS A(aData AS A) IF TYPEOF(aData)="C" TrimCRLFs = STRITRAN(aData,CRLF()," ") ELSE TrimCRLFs = aData END IF END FUNCTION FUNCTION cGetArgs AS C(pTableDef AS P,pContext AS P) DIM cFilter AS C = pTableDef.Filter FOR EACH x IN pTableDef.pArgs.arrArgs IF (":"+x.Name) $ pTableDef.Filter x.Value = A5_ArgGetValue(x,pContext) cFilter = STRITRAN(cFilter,":"+x.Name,x.Value) END IF NEXT cGetArgs = cFilter END FUNCTION %code% vLastname = "" DIM pFuncObj AS P = COMPILE_TEMPLATE(cFuncSrc) DIM aContents[1] AS P DIM CurSrtFld AS C = "Lastname" DIM CurSrtDir AS C = "AB" DIM pTableDef AS P DIM pTableDef.cRetValExp AS C = "Customer_ID" DIM pTableDef.FieldList AS C = <<%txt% LASTNAME FIRSTNAME COMPANY %txt% DIM pTableDef.TitleRow AS C = "{WIDTH=1.5}Last name|{WIDTH=1.3}First name|{WIDTH=1.3}Company" DIM pTableDef.Arguments AS C = <<%txt% <lastbutton="ok"> <arrArgs<[1]<Name="argLastname"> <DataType="Character"> <Source="Variable"> <SourceDisplay="Get value from variable"> <VariableScope="Session Variable"> <VariableName="vLastname"> <VariableWithScope="vLastname (Session Variable)"> <DefaultValue=""> <Prompt=.F.> <PromptText=""> <PromptControlType="Text Box"> <PromptChoices=""> <PromptDlgTitle="Missing Argument"> <PromptTextAbove=""> <PreviewValue=""> > > %txt% DIM pTableDef.pArgs AS P property_from_string(pTableDef.pArgs,pTableDef.Arguments) DIM pTableDef.TableName AS C = "customer" DIM pTableDef.Filter AS C = "LEFT(Lastname,LEN(\":argLastname\"))=\":argLastname\" .AND. (recno() > 0)" ' recno() > 0 is required in order to avoid showing deleted variables DIM pTableDef.Order AS C = "LASTNAME+FIRSTNAME" pLV.titlerow = pTableDef.titlerow pLV.titleevents = "Sort_LASTNAME|Sort_FIRSTNAME|Sort_COMPANY" 'pLV.style = "report,singlesel,showselalways,gridlines,fullrowselect" pLV.style = "report,singlesel,showselalways,fullrowselect" pLV.dragbehaviour = "" pLV.dropbehaviour = "" pLV.contents = pFuncObj.cGetContents(pTableDef,aContents,LOCAL_VARIABLES()) pLV.events = <<%code% FUNCTION OnRightClick AS C(pLV AS P,pListView AS P,pArgs AS P) WITH pLV pListView.Selection = pListView.GETROWVALUE(pArgs.GETCLICKROW()) OnSelectionChanged(pLV,pListView) UI_MSG_BOX("OnRightClick",pListView.Selection) END WITH END FUNCTION FUNCTION OnDoubleClick AS C(pLV AS P,pListView AS P,pArgs AS P) WITH pLV vListview = pListView.GETROWVALUE(pArgs.GETCLICKROW()) UI_MSG_BOX("OnDoubleClick","vListview="+vListview+CRLF()+"pArgs.GETCLICKROW()="+pArgs.GETCLICKROW()+CRLF()+"pListView.Selection="+pListView.Selection) END WITH END FUNCTION FUNCTION OnSelectionChanged AS V(pLV AS P,pListView AS P) WITH pLV vListview = pListView.Selection END WITH END FUNCTION FUNCTION OnKeyDown AS V(pVars AS P,pListView AS P,pArgs AS P) DIM cKey AS C DIM cKeyName AS C cKey = pArgs.GETKEYNAME() cKeyName = cKey IF cKey="{Num Del}" cKeyName = "{Delete}" ELSE IF pArgs.KEYCODE=13 cKeyName = "{Enter}" ELSE IF pArgs.KEYCODE=8 cKeyName = "{Backspace}" END IF UI_MSG_BOX("OnKeyDown",cKeyName) END FUNCTION %code% DIM cHdgTxt AS C = "Start typing the desired last name in the box below..." DIM cDlgNam AS C = "Find Customer" varC_result = UI_DLG_BOX(cDlgNam,<<%dlg% {watch=vLastname!refresh} {auto_external_refresh} {can_exit=close} {region0} {region_xmargin=.5} {region_ymargin=.5} {region1} {text=95,1:cHdgTxt}; {lf}; {endregion1}; {region2} Type partial last name:| [.40vLastname]; {lf}; Select Customer:| {listview=82,20vListview^=pLV}|; {endregion2}; {line=1,0}; {region3} {sp} <*20&Generate Invoice!ok> {sp=5} <15&Cancel!cancel> {endregion3}; {endregion0}; %dlg%,<<%code% IF LEFT(a_dlg_button,LEN("Sort_"))="Sort_" UI_MSG_BOX(a_dlg_button+" 1","vLV.aContents="+pFuncObj.cDumpPropArray(aContents)) pFuncObj.cDoSort(CurSrtFld,CurSrtDir,SUBSTR(a_dlg_button,LEN("Sort_")+1), \ pTableDef,aContents) UI_MSG_BOX(a_dlg_button+" 2",pFuncObj.cDumpPropArray(aContents)) a_dlg_button = "" END IF IF a_Dlg_button="refresh" pLV.CONTENTS = pFuncObj.cGetContents(pTableDef,aContents,LOCAL_VARIABLES()) a_dlg_button = "" END IF IF a_dlg_button="ok" UI_MSG_BOX(a_dlg_button,"RETURN: vListview: "+vListview) END IF IF a_dlg_button="cancel" 'UI_MSG_BOX(a_dlg_button,"") END IF IF a_dlg_button="close" 'UI_MSG_BOX(a_dlg_button,"") END IF %code%) END
I don't expect anyone to go over the whole thing, but I'm open to any suggestions for improving the code.
Thanks for looking!
-jimc
Comment