| Autor |
Beitrag |
jcop
      
Beiträge: 27
WinXP, Vista
Delphi 2009, Vb.NET
|
Verfasst: Mi 07.10.09 11:29
Hello All,
Is it possible to adjust the below code so I can reuse this on a formactivate?
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
| procedure TMainForm.act_FolderExecute(Sender: TObject); begin acft.trv_Folder.Visible := true; acft.trv_Manufacturer.Visible := false; acft.trv_Variation.Visible := false; acft.trv_Type.Visible := false; act_Folder.Checked := true; RG_ViewAcftBy.Caption := 'View Aircrafts By ... Folder'; end;
procedure TMainForm.act_ManufacturerExecute(Sender: TObject); begin acft.trv_Folder.Visible := false; acft.trv_Manufacturer.Visible := true; acft.trv_Variation.Visible := false; acft.trv_Type.Visible := false; act_Manufacturer.Checked := true; RG_ViewAcftBy.Caption := 'View Aircrafts By ... Manufacturer'; end;
procedure TMainForm.act_TypeExecute(Sender: TObject);
begin acft.trv_Folder.Visible := false; acft.trv_Manufacturer.Visible := true; acft.trv_Variation.Visible := false; acft.trv_Type.Visible := true; act_Type.Checked := true; RG_ViewAcftBy.Caption := 'View Aircrafts By ... Type'; end;
procedure TMainForm.act_VariationExecute(Sender: TObject); begin acft.trv_Folder.Visible := false; acft.trv_Manufacturer.Visible := false; acft.trv_Variation.Visible := true; acft.trv_Type.Visible := false; act_Variation.Checked := true; RG_ViewAcftBy.Caption := 'View Aircrafts By ... Variation'; end; |
I was thinking on a case structure, so when I click the Variationexecute the procedure can change my
controls as now, but I also want to load the last View when I restart my app, but this means at this stage
that I have to rewrite every line again. (copy/paste)
somebody has an idea?
regards,
Johan
|
|
BenBE
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Mi 07.10.09 12:07
jcop hat folgendes geschrieben : | Hello All,
Is it possible to adjust the below code so I can reuse this on a formactivate? |
At first we should optimize this a bit:
Given the four types of procedures we define:
Delphi-Quelltext 1:
| type TExecType = (exFolder, exManufacturer, exVariation, exType); |
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| procedure TMainForm.act_DoExecute(execKind: TExecType); const ViewCaption: array[TExecType] of String = ('Folder', 'Manufacturer', 'Variation', 'Type'); begin acft.trv_Folder.Visible := execKind = exFolder; acft.trv_Manufacturer.Visible := execKind = exManufacturer; acft.trv_Variation.Visible := execKind = exVariation; acft.trv_Type.Visible := execKind = exType; TCheckBox(FindComponent('act_' + ViewCaption[execKind])).Checked := true; RG_ViewAcftBy.Caption := 'View Aircrafts By ... ' + ViewCaption[execKind]; end; |
jcop hat folgendes geschrieben : |
I was thinking on a case structure, so when I click the Variationexecute the procedure can change my
controls as now, but I also want to load the last View when I restart my app, but this means at this stage
that I have to rewrite every line again. (copy/paste)
somebody has an idea?
regards,
Johan |
Call of this by
Delphi-Quelltext 1:
| act_DoExecute(exFolder); |
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
jcop 
      
Beiträge: 27
WinXP, Vista
Delphi 2009, Vb.NET
|
Verfasst: Mi 07.10.09 12:39
Hi BenBe,
Thanks for this EG. I basicly don't understand what you have created but it seems to work, except for following line.
Delphi-Quelltext 1:
| TCheckBox(FindComponent('act_' + ViewCaption[execKind])).Checked := true; |
If I put this in comment then the selection works, however I saw that you used a TcheckBox, but the components
that trigger this view state are csradiobuttons, placed on a ribbon, I've tried to change the code to following
Delphi-Quelltext 1:
| TRadioButton(FindComponent('act_' + ViewCaption[execKind])).Checked := true; |
but this also throws erorrs, can you explain this line, so I know where/how to adjust, cause I think that the code
cannot find the components refered to. (The error is a EAccessViolation, read of address 00000000).
But again thanks for this eg.
Johan
|
|
BenBE
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Mi 07.10.09 12:49
jcop hat folgendes geschrieben : | Hi BenBe,
Thanks for this EG. I basicly don't understand what you have created but it seems to work, except for following line. |
The type declaration is a so-called Enum type.
The Const array is an Array of string indexed by this enum type, i.e. instead of integers the different elements of the enum form the indexing.
The assignments for the visibility are just plain boolean assignments; not too hard to understand if you have a look at the Object Pascal Reference that should be included as part of the Delphi documentation.
jcop hat folgendes geschrieben : | Delphi-Quelltext 1:
| TCheckBox(FindComponent('act_' + ViewCaption[execKind])).Checked := true; |
If I put this in comment then the selection works, however I saw that you used a TcheckBox, but the components
that trigger this view state are csradiobuttons, placed on a ribbon, I've tried to change the code to following
TRadioButton(FindComponent('act_' + ViewCaption[execKind])).Checked := true;
but this also throws erorrs, can you explain this line, so I know where/how to adjust, cause I think that the code
cannot find the components refered to. (The error is a EAccessViolation, read of address 00000000).
But again thanks for this eg.
Johan |
The line mentioned actually consists of two parts:
The first part is the FindComponent call which seems to make trouble while the second part is nothing else than your basic source.
Let's split this up a bit:
TRadioButton(expr): Typecast the expression within to "return" an object of this type.
FindComponent(string): Lookup a component in the current object instance with the name given by "string".
'act_' + ViewCaption[execKind]: The name of the component we look for. For simplicity we build it from the const array we already have and the prefix used for the different components.
What might make problems and thus should be a starting point for debugging is whether the innermost part (the name) is build properly AND is actually the name of the component we need. The additional check for the right typecast is another factor to take into account.
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
jcop 
      
Beiträge: 27
WinXP, Vista
Delphi 2009, Vb.NET
|
Verfasst: Mi 07.10.09 13:43
|
|
|