Get Form Name as variable and Open the Form

I'm using a ListView component with multiple items in it. The contents of the ListView depends on what item is selected in a TreeView. (So the ListView can change dynamically.) I want to link every item in the listview to a form name, and then depending on what item gets double clicked, the associated form must open. Is it possible to do this without If..Then or Case etc. statements, as I'm talking about a lot of forms here! I was hoping to use a variable or something that gets the form name from the SubItem of the Treeview and then create the form. Please Help Urgently!!
jannie030200Asked:
Who is Participating?
 
zb_russiaConnect With a Mentor Commented:
I are sorry for bad English, I not absolutely correctly have understood your question (small colloquial practice).

As it seems, there is a most simple mode to load the form, on her name (not the variant is considered, when there is a loading of a stream, the names of classes and so on) are formed dynamically. It - all the same problem case/of.

How it is possible to receive a name of a charged window? If this window is present as a name of the element in ListView (then we simple use ListView.Selected.Name) and then through if Name = " we discover the outcome, necessary to us.

If we use a not obviously circumscribed name (as in your example), then the intermediate array (or table) is used, that again a problem to reduce to a call of the chosen window.

For a case with a loading from a stream (the storage of the form in a data base) me needs to be re-read Rey Konopka, I now fast can not recollect singularities of a realization of a loading and unloading of the form in a stream.
0
 
edeyCommented:
Name is the name of the control as referenced in the application’s code.

TComponentName: string;
property Name: TComponentName;



GL
Mike
0
 
zb_russiaCommented:
Sample:

  case ListView.Selected.Index of
    0: begin
      dlgGetCodeCard := TdlgGetCodeCard.Create( Self );
      try
        if ShowModal = mrOk ...
      finally
        dlgGetCodeCard.Free;
      end;
    end;
    1: begin
      ...
    end;
  end;


0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
jannie030200Author Commented:
Thanks Zb, but the reason why I don't want to use case statements for this (as I mentioned in my original question) is that the index of the selected Item may vary depending on what user is logged on to the program. So it is impossible to link say ViewList.Selected.Index (say selected index = 0) to a fixed frmName, because when the next user logs on that very same item might have an index of say 10. I hope this clarifies the problem a bit. If it is possible to do something with the case statement and I'm just being stupid, can you please give me a bit more of the code I need to do this.

I think that maybe Edey's comment is a step in the right direction, but I'm quite new to the Delphi Environment and haven't got the foggiest as to how to declare properties..

Thx
Jannie
0
 
kretzschmarCommented:
hi jannie,

each node has a data-property (type pointer). here you can append all you need also objects(forms) or typed records.

meikl
0
 
jannie030200Author Commented:
Thanks Zb, but the reason why I don't want to use case statements for this (as I mentioned in my original question) is that the index of the selected Item may vary depending on what user is logged on to the program. So it is impossible to link say ViewList.Selected.Index (say selected index = 0) to a fixed frmName, because when the next user logs on that very same item might have an index of say 10. I hope this clarifies the problem a bit. If it is possible to do something with the case statement and I'm just being stupid, can you please give me a bit more of the code I need to do this.

I think that maybe Edey's comment is a step in the right direction, but I'm quite new to the Delphi Environment and haven't got the foggiest as to how to declare properties..

Thx
Jannie
0
 
jannie030200Author Commented:
hi meikl

I feel like an idiot at this point in time but I'm really lost here!

I see that the data property thing will work. If I got a table that looks something like this:
ID  Descr     FormName
1   Options   frmOptions
2   Setup     frmSetup  etc etc

If the Item in the ListView has got the caption of the descr for eg. 'Options' , I can obviously lookup the record in the table and then see that 'frmOptions' is associated with the ListView Item. The FormName is stored as Text. How can I Read that FormName into the Data Property of the Item and use that Data property to open a form when I double click the Item.

If you can, please include some code to help me understand this.
Cheers.
0
 
julianpointerCommented:
When are you creating each form ...

do you have some code like this to create each instance of a form

Form:=TForm.Create(self)
Form.Show;


or do you load each form when the  application is created.

0
 
jannie030200Author Commented:
Hi Julian,

the forms should bw created at runtime and by looking at your statement,
Form:=TForm.Create(Self)
Form.Show;

I need Form to be anything depending on what Item in the listview gets double clicked for eg.

frmMain := TfrmMain.Create(Self) and then the next time i click on the Icon it might need to execute something lik

frmNew := TfrmNew.Create(self);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.