Board index » delphi » Help! Pointers to objects
d...@delbruck.pharm.sunysb.edu (David Eisenberg)
![]() Delphi Developer |
Sat, 11 Jul 1998 03:00:00 GMT
|
d...@delbruck.pharm.sunysb.edu (David Eisenberg)
![]() Delphi Developer |
Sat, 11 Jul 1998 03:00:00 GMT
Help! Pointers to objects
Okay, am I a moron?? I want to mimic an indexed array of label
objects, like Visual Basic can do with its Index property. I declare: Type MyWindow = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; var Procedure FormCreate (yes, I've tried it in FormActivate and Then, I reference them like this: I get a GPF on the above line marked with a '*'. Any ideas? Is this Thanks, |
Brien Ki
![]() Delphi Developer |
Sat, 11 Jul 1998 03:00:00 GMT
Re:Help! Pointers to objectsQuoted...@delbruck.pharm.sunysb.edu (David Eisenberg) wrote: TLabel. Delphi's objects by default are pointers. Remove the ^. Quote>Procedure FormCreate (yes, I've tried it in FormActivate and that points to the label. Quote>Then, I reference them like this: Quote>I get a GPF on the above line marked with a '*'. Any ideas? Is this Brien King bk...@primenet.com |
Matthias Rompp
![]() Delphi Developer |
Sun, 12 Jul 1998 03:00:00 GMT
Re:Help! Pointers to objectsIn article <4e3lkd$...@abel.cc.sunysb.edu>, d...@delbruck.pharm.sunysb.edu (David Eisenberg) wrote: Quote>Okay, am I a moron?? I want to mimic an indexed array of label var Labels: Array[1..3] of TLabel; .. MyWindow.Labels[1] := MyWindow.Label1; MyWindow.Labels[2] := MyWindow.Label2; MyWindow.Labels[3] := MyWindow.Label3; (untested) Regards, ---- |
David Ullric
![]() Delphi Developer |
Sun, 12 Jul 1998 03:00:00 GMT
Re:Help! Pointers to objectsQuoted...@delbruck.pharm.sunysb.edu (David Eisenberg) wrote: pointers to objects already. You should be able to say var and later MyWindow.Labels[1] := MyWindow.Label1; and MyWindow.Labels[1].Caption := 'Hi there This is label 1.'; instead. Not that what you're doing is illegal, but you're using pointers You say you "declare" Type Does this mean that you're not adding the labels to the form in the IDE? If you really want to create them at runtime you need to Create them. Label1:=TLabel.Create; (in the Form.OnCreate, say). Then you would have to set their size and postion, Just to be certain I hadn't left anything out I made a form with an type var implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); An array[1..3] is the same but more so. |
Michael Chap
![]() Delphi Developer |
Mon, 13 Jul 1998 03:00:00 GMT
Re:Help! Pointers to objectsIn article <4e3lkd$...@abel.cc.sunysb.edu>, d...@delbruck.pharm.sunysb.edu (David Eisenberg) wrote: Quote>Okay, am I a moron?? I want to mimic an indexed array of label Labels: Array[1..3] of TLabel; Quote>Procedure FormCreate (yes, I've tried it in FormActivate and Quote>Then, I reference them like this: Object Pascal. This becomes really apparent when you are trying to use Sizeof(TLabel) and get back a value of 4. You were actually placeing pointers to pointers in the array. ----------------------------------------------- Not the end of the earth but you can see it from |
Ari Hirviniem
![]() Delphi Developer |
Thu, 16 Jul 1998 03:00:00 GMT
Re:Help! Pointers to objectsQuoteDavid Eisenberg wrote: Type Procedure TMyWindow.FormCreate... Tip of the day: Insert following code to FormCreate: for i := 1 to NumOfLabels do Now you can find out index of label in event procedures: procedure LabelClick(Sender: TObject); -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |