Jump to content

Recommended Posts

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

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

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;
 

 

  • Like 1

Share this post


Link to post
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

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 ?

 

QuickRep.jpg.0703ed21c8938afbfbf443b071623ee4.jpg

Edited by Henry Olive

Share this post


Link to post

Put the StrUtils into the uses of the implementation section or at least after QrCtrls.

Share this post


Link to post

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

You could fully qualify the call.

 

System.SysUtils.SplitString( ...

 

Sorry, brainfart:
System.StrUtils.SplitString( ...

  • Like 1

Share this post


Link to post

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

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

Where is System.SysUtils.SplitString( ... ??? I don't see it there.

Share this post


Link to post
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
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

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

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 by programmerdelphi2k
  • Sad 1

Share this post


Link to post

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.)

 

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×