Autor Beitrag
prebbe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Di 11.09.07 12:59 
Hi!

I have a class, say TExample, with variables fName, fID, fString ++

I want to make several instances of TExample like this example:

TExamples:
no. 1: fName='test' fID=1 fString='this is a test'
no. 2: fName='3ysdfgh' fID=2 fString='this is a teawegfst'
no. 3: fName='w45y' fID=3 fString='this isasdfgagfa a test'
no. 4: fName='asdfg a' fID=4 fString='this is a teasgst'

i can simply do like this:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TEST;
var test, test2: TExample;
begin
  test := TExample.Create;
  test.fname := 'test';
  test.fID := 1;
  test.fString := 'this is a test';

  test2 := TExample.Create;

  //and so on with all the four
end;


But what if i don't know how many i shall create?
At runtime, maybe it is one hundred, maybe just one or two.
Can i make an array of TExample? and use the number in the array
as id for each TExample?

Can anyone provide me with a small example of this application please?


Zuletzt bearbeitet von prebbe am Di 11.09.07 13:09, insgesamt 1-mal bearbeitet
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 11.09.07 13:04 
please use the "delphi code mode" for posting youre source code ! :D
Critter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 328
Erhaltene Danke: 3

Windows 7
Delphi 7 Pro.
BeitragVerfasst: Di 11.09.07 13:48 
Hello,
user profile iconprebbe hat folgendes geschrieben:
Can i make an array of TExample? and use the number in the array
as id for each TExample?

yes that is an posible way. Just defin a dynamic array (MyArray : array of TExample) and set the size at runtime using the setlenth comand (setlength(MyArray, 100);).

You can also use Delphis tObjectList class to manage your objects. This could be the more easy way. Just have a look at your Delphi-Help.

critter