Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General Discussion » View Thread |
Messages 1 to 4 of 4 total |
same code for two tables: better way? |
Fri, Jan 11 2008 2:42 AM | Permanent Link |
"Harry de Boer" | LS
As you can see in the code below I have two tables with fields 'selected' that needs the same operation (based on which tabsheet the user is). I now duplicate the code and only change the tablename. Is there a better way of doing this (using the codeblock only once) ? I thought at first to make a function and pass the tablename, but then I gave to create a lot of functions throughout the app. Read something about using pointers but I'm not sure how to use them regarding this matter. So, how would you do this? Regards, Harry if tabCTRL.ActivePageIndex = 0 then begin //klanten with Klanten do begin DisableControls; First; while not Eof do begin Edit; fieldvalues['Selected'] := TRUE; Post; Next; end; First; EnableControls; end; end else begin //artikelen with Artikelen do begin DisableControls; First; while not Eof do begin Edit; fieldvalues['Selected'] := TRUE; Post; Next; end; First; EnableControls; end; end; |
Fri, Jan 11 2008 11:02 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Harry
Two different ideas suggest themselves 1. You can pass a TDBISAMTable as a parameter to a procedure/function so your code could be altered like if tabCTRL.ActivePageIndex = 0 then DoSelect(Klanten) else DoSelect(Artikelen) with a procedure defined as follows procedure TForm1.DoSelect(ChosenTable:TDBISAMTable); begin with ChosenTable do begin DisableControls; First; while not Eof do begin Edit; fieldvalues['Selected'] := TRUE; Post; Next; end; First; EnableControls; end; end; 2. You could use SQL and simply substitute the table name (NOTE you can't use parameters for the table name). Roy Lambert |
Sat, Jan 12 2008 6:02 AM | Permanent Link |
"Harry de Boer" | Thanks Roy. Much appreciated.
Regards, Harry "Roy Lambert" <roy.lambert@skynet.co.uk> schreef in bericht news:5F18CD2F-7540-4BB6-8EE7-8D3D14F11AF4@news.elevatesoft.com... > Harry > > > Two different ideas suggest themselves > > 1. You can pass a TDBISAMTable as a parameter to a procedure/function so your code could be altered like > > if tabCTRL.ActivePageIndex = 0 then DoSelect(Klanten) else DoSelect(Artikelen) > > with a procedure defined as follows > > procedure TForm1.DoSelect(ChosenTable:TDBISAMTable); > begin > with ChosenTable do begin > DisableControls; > First; > while not Eof do begin > Edit; > fieldvalues['Selected'] := TRUE; > Post; > Next; > end; > First; > EnableControls; > end; > end; > > 2. You could use SQL and simply substitute the table name (NOTE you can't use parameters for the table name). > > Roy Lambert > |
Sun, Jan 13 2008 5:53 AM | Permanent Link |
"Harry de Boer" | LS
Came up with another one. Mostly a Tdatasource is used for databound controls but in this way you could also use it: if tabCTRL.ActivePageIndex = 0 then datasource1.dataset := Klanten else datasource1.dataset := Artikelen; with datasource1.dataset do begin ..... Regards, Harry "Roy Lambert" <roy.lambert@skynet.co.uk> schreef in bericht news:5F18CD2F-7540-4BB6-8EE7-8D3D14F11AF4@news.elevatesoft.com... > Harry > > > Two different ideas suggest themselves > > 1. You can pass a TDBISAMTable as a parameter to a procedure/function so your code could be altered like > > if tabCTRL.ActivePageIndex = 0 then DoSelect(Klanten) else DoSelect(Artikelen) > > with a procedure defined as follows > > procedure TForm1.DoSelect(ChosenTable:TDBISAMTable); > begin > with ChosenTable do begin > DisableControls; > First; > while not Eof do begin > Edit; > fieldvalues['Selected'] := TRUE; > Post; > Next; > end; > First; > EnableControls; > end; > end; > > 2. You could use SQL and simply substitute the table name (NOTE you can't use parameters for the table name). > > Roy Lambert > |
This web page was last updated on Friday, April 19, 2024 at 07:09 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |