Henry Olive 5 Posted January 7, 2023 Good Day, Delphi 10.3 Below codes works w/o any problem Edit1.Text := '22-1568'; Edit2.Text := SplitString(Edit1.Text,'-')[0]; // result= 22 Edit3.Text := SplitString(Edit1.Text,'-')[1] // result:= 1568 When i try the same code like below ( *There is StrUtils in Uses* ) I'm getting Not enough actual parameters error msg. Str := CDS1.FieldByName('DOCNO').asString; // which is '22-1568' LeftStr := SplitString(Str,'-') [0]; RightStr := SplitString(Str,'-') [1]; What am i doing wrong ? Thank You Share this post Link to post
Uwe Raabe 2057 Posted January 7, 2023 LeftStr and RighStr are functions declared in StrUtils. Share this post Link to post
Henry Olive 5 Posted January 7, 2023 Thank you so much Uwe I changed the var names to var MyStr, LeftMyStr, RightMyStr but i still get the same error msg. Thank You Share this post Link to post
Lars Fosdal 1792 Posted January 7, 2023 I'd use a helper array to avoid running the split twice. var Splits: TArray<string>; begin Splits := SplitString(MyStr,'-'); LeftMyStr := Splits[0]; RightMyStr := Splits[1]; end; 1 Share this post Link to post
Uwe Raabe 2057 Posted January 7, 2023 1 hour ago, Henry Olive said: but i still get the same error msg. In that case you need to show more of your code. Share this post Link to post
Henry Olive 5 Posted January 7, 2023 (edited) Thank you SO MUCH Lars, Uwe After i get the same error with Lars's suggestion i noticed below situation When i move my mouse cursor on SplitString in Delphi Editor, i saw Delphi shows Quick Report's SplitString In my uses there are QRCtrls, QuickRpt, StrUtils and i need to use a quickreport in that Unit. I also tried to change StrUtils in Uses to System.StrUtils but still get the same error What should i do now ? Edited January 7, 2023 by Henry Olive Share this post Link to post
Uwe Raabe 2057 Posted January 7, 2023 Put the StrUtils into the uses of the implementation section or at least after QrCtrls. Share this post Link to post
Henry Olive 5 Posted January 7, 2023 Thank you SO MUCH Uwe, i'm really very very sorry for taking your time I added StrUtils at the end of the main Uses Clause but i get the same error I deleted StrUtils in the main Uses Clause and added uses of the implementation section but i get the same error Share this post Link to post
Uwe Raabe 2057 Posted January 7, 2023 Can you show both uses clauses of that unit? Share this post Link to post
Lars Fosdal 1792 Posted January 7, 2023 You could fully qualify the call. System.SysUtils.SplitString( ... Sorry, brainfart: System.StrUtils.SplitString( ... 1 Share this post Link to post
Henry Olive 5 Posted January 7, 2023 Thank you so much Uwe interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, DBCtrls, ToolWin, StdCtrls, ExtCtrls, Mask, Buttons, Grids, DBGrids, Menus, DB, DBClient,TypInfo, QRCtrls, QuickRpt, Math, FMTBcd, SqlExpr, Provider, System.Actions, Vcl.ActnList; type ..... implementation {$R *.dfm} Uses System.StrUtils, Udm, UItemCard, ULookUp; Share this post Link to post
Henry Olive 5 Posted January 7, 2023 Thank you so much Lars I tried System.StrUtils.SplitString('-', MyStr) [0]; but still get the same error If i remove QRCtrls, QuickRpt from Uses, below codes work fine w/o any error MyStr := CDS1.DataSet.FieldByName('DOCNO').AsString; MyLeftStr := SplitString('-',MyStr) [0]; MyRightStr := SplitString('-',MyStr) [1]; Share this post Link to post
Stano 143 Posted January 7, 2023 Where is System.SysUtils.SplitString( ... ??? I don't see it there. Share this post Link to post
Lars Fosdal 1792 Posted January 7, 2023 3 minutes ago, Stano said: Where is System.SysUtils.SplitString( ... ??? I don't see it there. I meant to write System.StrUtils.SplitString( ... Share this post Link to post
Uwe Raabe 2057 Posted January 7, 2023 14 minutes ago, Henry Olive said: Thank you so much Lars I tried System.StrUtils.SplitString('-', MyStr) [0]; but still get the same error If i remove QRCtrls, QuickRpt from Uses, below codes work fine w/o any error MyStr := CDS1.DataSet.FieldByName('DOCNO').AsString; MyLeftStr := SplitString('-',MyStr) [0]; MyRightStr := SplitString('-',MyStr) [1]; The calls to SplitString look as if the parameters need to be switched. First parameter is expected to be the string to be split, while second is the string with the separators. Note that the QuickReport implementation allows only a Char for the separator, while the StrUtils one allows multiple separators. Share this post Link to post
Stano 143 Posted January 7, 2023 (edited) Sorry Lars Fosdal, but that was for Henry Olive. Edited January 7, 2023 by Stano Share this post Link to post
Lars Fosdal 1792 Posted January 7, 2023 If you Ctrl-Click on the SplitString - where do you end up? What if you add StrUtils at the end of the uses section? The behaviour you describe is a bit baffling, tbh. Share this post Link to post
programmerdelphi2k 237 Posted January 7, 2023 (edited) you can try a home-made like this: Put it in a "unit XXXX" used by your code... if you dont use last IDE, as 10 or 11 else, you can use : MyResult := MyVarWithTextSeparatedByXXX.Split(['-']); // MyResult: TArray<string>; type TMyArrOfStr = array of string; // for easy usage on many places... Note: Delphi use type-name to identify same types on var/object function MySplitStringToArrays(const AValue: string; ASeparator: char = '-'): TMyArrOfStr; var LText : string; i, z : integer; begin result := []; // if Trim(AValue) = '' then exit; // i := 1; // begin repeat z := Pos(ASeparator, AValue, i); if (z > 0) then begin LText := Copy(AValue, i, z - i); i := z + 1; end else begin LText := Copy(AValue, i); end; // if Trim(LText) <> '' then result := result + [LText]; until (z = 0); end; end; procedure TForm1.Button1Click(Sender: TObject); var MyResult: TMyArrOfStr; MyText : string; begin MyText := '-- --'; // hello-world-from-Delphi- -'; // MyResult := MySplitStringToArrays(MyText, '-'); // Memo1.Text := 'Arrays=' + Length(MyResult).ToString; Memo1.Lines.AddStrings(MyResult); end; Edited January 7, 2023 by programmerdelphi2k 1 Share this post Link to post
Henry Olive 5 Posted January 8, 2023 Thank You SO SO SO MUCH Uwe, Lars, Programmer I solved the problem as below 1- In Uses, I changed StrUtils to System.StrUtils in USES 2- In Uses, I moved QRCtrls, QuickRpt units BEFORE System.StrUtils (as Uwe said.) 3- In codes, I used System.StrUtils.SplitString( ... , ... ) (as Lars said.) 1 Share this post Link to post