| |

VerySource

 Forgot password?
 Register
Search
View: 728|Reply: 2

Ask how to assign a function to an array?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Russia

Post time: 2020-1-25 23:20:02
| Show all posts |Read mode
Type
   CurrList = record
      iID: Integer;
      cCode: String;
      cField1: String;
      cField2: String;

Var
   Curr500: Array Of CurrList;

function LoadComboBox (ObjCurr: array of CurrList; ado: TAdoQuery): Boolean;
var
   iCount: integer;
begin
   iCount: = 0;
   ado.First;
   While Not ado.Eof Do
   Begin
      iCount: = iCount + 1;
      ObjCurr [iCount-1] .iID: = ado.FieldByName ('iID'). AsInteger;
      ObjCurr [iCount-1] .cField1: = ado.FieldByName ('cField1'). AsString;
      ado.Next;
   End;
end;

// Init operation
SetLength (Curr500, ado.RecordCount);
LoadComboBox (Curr500, ado);
 
// Is Curr500 empty when called?
Edit1.text: = Curr500 [iIndex] .cField1;

// thanks
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-15 22:00:01
| Show all posts
With reference parameters. As follows: (note an extra var)

function LoadComboBox (var ObjCurr: array of CurrList; ado: TAdoQuery): Boolean;
....
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-15 23:45:01
| Show all posts
Test passed:

Type
   CurrList = record
      iID: Integer;
      cCode: String;
      cField1: String;
      cField2: String;
end;

function LoadComboBox (var ObjCurr: array of CurrList): Boolean;
var
   iCount: integer;
begin
   for iCount: = 1 to 11 Do
   Begin
      ObjCurr [iCount-1] .iID: = iCount;
      ObjCurr [iCount-1] .cField1: = IntToStr (iCount);
   End;
end;

procedure TForm1.Button1Click (Sender: TObject);
var
  Curr500: Array [1..11] Of CurrList;
begin
  LoadComboBox (Curr500);
  Edit1.text: = Curr500 [1] .cField1;
end;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list