Recent

Author Topic: How can i find (or select ) Array with name??  (Read 5990 times)

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: How can i find (or select ) Array with name??
« Reply #15 on: January 22, 2019, 12:47:48 am »
Aserge was correct in the approach that was offered.

Use  a TStringList

And ether use your own look search or use something like "Values" property where each one will return the
value of the define..
for example

VO1_1111=S04,V08,S10

That would be a line in stringlist.., You may need to quote it..

In the object inspector you can predefine these lines in the editor or load them from file.

So use
MyValues := MYStringList.Values('V01_1111');

After this, MYVALUES should equal S04,V08,S10 etc...

from that you can partition the string since they are all the same size or use a comma separator read code.

The only true wisdom is knowing you know nothing

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: How can i find (or select ) Array with name??
« Reply #16 on: January 22, 2019, 08:11:45 am »
Hi

i have many array like these :
Code: Pascal  [Select][+][-]
  1. const
  2.   //----- Verb 2 ----------------
  3.   {V01 = Verb 1 ___ 11 = Group 11 ___ 11 = + ___ 12 = -}
  4.  
  5. can anybody help or guide me how can i select array with name
  6. [/quote]
  7. Before to get a proper solution, please tell us what you're doing with the array's
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: How can i find (or select ) Array with name??
« Reply #17 on: January 22, 2019, 01:08:04 pm »
Code: [Select]
[quote author=mangakissa link=topic=43914.msg308902#msg308902 date=1548141105]
[quote author=majid.ebru link=topic=43914.msg308144#msg308144 date=1547528781]
Hi

i have many array like these :
const
  //----- Verb 2 ----------------
  {V01 = Verb 1 ___ 11 = Group 11 ___ 11 = + ___ 12 = -}
[/quote]
can anybody help or guide me how can i select array with name

Before to get a proper solution, please tell us what you're doing with the array's


i tell in the first post

i have many tables and i read form them with array.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: How can i find (or select ) Array with name??
« Reply #18 on: January 22, 2019, 01:25:08 pm »
It is not clear what you are trying to do.
However, if you want to use record constants (?) you have to pre-declare them.
You cannot create such constants on-the-fly in an event handler.
Are you looking for something like the following?
Code: Pascal  [Select][+][-]
  1. type
  2.  
  3.    TVerb = record
  4.      Name: string[10];
  5.      Arry: array of String;
  6.    end;
  7.    TVerbList = array of TVerb;
  8.  
  9. const
  10.  
  11.   Verb0: TVerb = (Name:'V01_1111'; Arry:('S04','V08','S10'));
  12.   Verb1: TVerb = (Name:'V01_1121'; Arry:('S06','V08','S10','V09','S15'));
  13.  
  14. type
  15.  
  16.   TForm1 = class(TForm)
  17.                 Button1: TButton;
  18.                 procedure Button1Click(Sender: TObject);
  19.   private
  20.     VerbList: TVerbList;
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. procedure TForm1.Button1Click(Sender: TObject);
  29. begin
  30.   SetLength(VerbList, 2);
  31.   VerbList[0] := Verb0;
  32.   VerbList[1] := Verb1;
  33. end;

 :D :) ;D

i have error

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How can i find (or select ) Array with name??
« Reply #19 on: January 22, 2019, 01:56:26 pm »
I am using FPC 3.2.0
Perhaps you have an earlier version which does not support dynamic array constants with that syntax?

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: How can i find (or select ) Array with name??
« Reply #20 on: January 22, 2019, 11:41:47 pm »
Code: Pascal  [Select][+][-]
  1. TVerb = record
  2.    Name:String[10];
  3.    V:Array[0..4] of String[4]; //define array to its longest possible length;
  4.   End;
  5. Const
  6.    Verbs :Array[0..1] of TVerb =
  7.       ( (Name:'V01_1111';V:('S04','V08','S10','','')),
  8.         (Name:'V01_1121';V:('S06','V08','S10','V09','S15'))
  9.       );
  10. var
  11.   Form1: TForm1;
  12.  
  13. implementation
  14.  
  15. {$R *.lfm}
  16.  
  17. Function GetVerbIndex(Verb:String):Integer;
  18. Var
  19.   I:Integer;
  20. Begin
  21.  For I := Low(Verbs) to  high(Verbs) do
  22.   If Verbs[I].Name =Verb then
  23.    begin
  24.      Result := I;
  25.      Exit;
  26.    End;
  27.  Result := -1;
  28. End;
  29. Function GetVerbValue(Index:Integer; ValueIndex:Integer):String;
  30. Begin
  31.   Result := '';
  32.   If (Index < 0)or(ValueIndex < Low(TVerb.V)) or (ValueIndex > High(TVerb.V)) Then exit;
  33.   Result := Verbs[Index].V[ValueIndex];
  34. end;
  35.  
  36. { TForm1 }
  37.  
  38.  
  39. procedure TForm1.Button1Click(Sender: TObject);
  40. begin
  41.  Caption := GetVerbValue(GetVerbIndex('V01_1111'),1);
  42. end;                                          
  43.  

You twisted my arm! I hate seeing a grown person cry!  :D

Please study code and you'll how to expand it.
The only true wisdom is knowing you know nothing

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: How can i find (or select ) Array with name??
« Reply #21 on: January 23, 2019, 11:25:47 am »
My contribution to the whole thing.
I created a class, which can be declared as an object. The 'const' arrays are read into a TList. This is hardcoded, just like using 'const array's'.
I put a small demo as attachement.
Code: Pascal  [Select][+][-]
  1. unit constarray;
  2.  
  3. interface
  4.  
  5. uses classes;
  6.  
  7. type
  8.  
  9. TMyTableRecord = class
  10.   fName : string;
  11.   fSearchString : string;
  12. end;
  13.  
  14. TMyTableSearch = class
  15.   fRecords : TList;
  16.   fRec     : TMyTableRecord;
  17.  
  18.   private
  19.     procedure FillRecords;
  20.   public
  21.     constructor create;
  22.     destructor  destroy; override;
  23.  
  24.     function  GetRecord(const aName : string) : boolean;
  25.     function  Table(const aIndex : smallint) : string;
  26.     function  Get(const aName : string; const aValue : smallint) : string;
  27.  
  28. end;
  29.  
  30. implementation
  31.  
  32. { TMyTableSearch }
  33.  
  34. constructor TMyTableSearch.create;
  35. begin
  36.   fRecords := TList.Create;
  37.   FillRecords;
  38. end;
  39.  
  40. destructor TMyTableSearch.destroy;
  41. var index : smallint;
  42. begin
  43.   for index  := 0 to fRecords.Count - 1 do
  44.     TMyTableRecord(fRecords[index]).Free;
  45.   fRecords.Free;
  46.   inherited;
  47. end;
  48.  
  49. procedure TMyTableSearch.FillRecords;
  50.  
  51. procedure Add(const aName, aValue : string);
  52. var Rec : TMyTableRecord;
  53. begin
  54.   Rec := TMyTableRecord.Create;
  55.   rec.fName         := aName;
  56.   rec.fSearchString := aValue;
  57.   fRecords.Add(Rec);
  58. end;
  59.  
  60. begin
  61.   Add('V021111','V17,V08,V19');
  62.   Add('V021112','V10,V17,V08,V19');
  63.   Add('V021121','V08,V09,V19');
  64.   Add('V021122','V10,V08,V09,V19');
  65.   Add('V021131','V30,V08,V09');
  66.   Add('V021132','V10,S21,V08,V09');
  67.   Add('V021211','V08,V17,V12,V19');
  68.   Add('V021212','V08,V10,V17,V12,V19');
  69.   Add('V021221','V08,V09,V19');
  70.   Add('V021222','V08,V10,V09,V19');
  71.   Add('V021231','V08,S21,V09');
  72.   Add('V021232','V08,V10,S21,V09');
  73.   Add('V021311','V08,V12,V19');
  74.   Add('V021312','V08,V10,V12,V19');
  75.   Add('V021321','V08,V09,V19');
  76.   Add('V021322','V08,V10,V09,V19');
  77.   Add('V021331','V08,S21,V09');
  78.   Add('V021332','V08,V10,S21,V09');
  79. end;
  80.  
  81.  
  82. function TMyTableSearch.Get(const aName: string;
  83.   const aValue: smallint): string;
  84. begin
  85.   GetRecord(aName);
  86.   result := Table(aValue)
  87. end;
  88.  
  89. function TMyTableSearch.getRecord(const aName : string) : boolean;
  90. var index : smallint;
  91. begin
  92.   fRec := nil;
  93.   result := false;
  94.   for index  := 0 to fRecords.Count - 1 do
  95.   begin
  96.     if TMyTableRecord(fRecords[index]).fName = aName then
  97.     begin
  98.       fRec := TMyTableRecord(fRecords[index]);
  99.       result := true;
  100.     end;
  101.   end;
  102. end;
  103.  
  104. function TMyTableSearch.Table(const aIndex: smallint): string;
  105. var sl : TStringlist;
  106. begin
  107.   sl := TStringlist.create;
  108.   result := '';
  109.   try
  110.     if fRec <> nil then
  111.     begin
  112.     sl.CommaText := frec.fSearchString;
  113.     if aIndex <= sl.Count then
  114.       result := sl[aindex - 1]
  115.     end;
  116.   finally
  117.     sl.Free;
  118.   end;
  119. end;
  120.  
  121. end.
  122.  
 
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: How can i find (or select ) Array with name??
« Reply #22 on: January 23, 2019, 05:11:20 pm »
thank you very much

i will try these codes.

 :-* %) :-* %) :) ;) :D ;D

 

TinyPortal © 2005-2018