Some Newbie Questions

1) Im doing
if edit1.text = '' or edit2.Text = '' or combobox1.Text = '' then begin

Im getting: Operator not applicable to this operand type

Why? and how to fix it?

2)In VB I used to do something like
Dim a() as String;

a is array but its not limited
how to do this is delphi?

3)In VB there was LONG and Integer
what is Long is Delphi?

4)Ive done this
U: array[0..500] of string;
F: TextFile;
x: Integer;
  x:=0;
  reset(f);
  repeat
    readln(F,U[x],P[x],D[x],M[x],Y[x]);
    x :=x+1;
  until Eof(f);
  ShowMessage(U[0]);
  ShowMessage(M[0]);

this text file has this
LINE1: Mike,Hello,3,5,1999
Line2: Jad,Hi,23,10,1980

its Username,Password,Day,Month,Year
all separated by commas
I thought the array would work, the username in U, Password in P and so on...
how to make it work???
peritoXAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
esoftbgConnect With a Mentor Commented:
4).
unit Unit1_Q_21188887;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo: TMemo;
    MemoUsers: TMemo;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure SplitStrings(Delimiter: Char; Input: string; SS: TStrings);
begin
   Assert(Assigned(SS));
   SS.Clear;
   SS.Delimiter := Delimiter;
   SS.DelimitedText := Input;
end;

procedure TForm1.Button1Click(Sender: TObject);
type
  TUserRec = record
    U:       string[32];
    P:       string[32];
    Y:       string[4];
    M:       string[2];
    D:       string[2];
  end;
var
  I:         Integer;
  J:         Integer;
  K:         Integer;
  N:         Integer;
  SL:        TStringList;
  URA:       array of TUserRec;
begin
   SL := TStringList.Create;
   try
     Memo.Lines.LoadFromFile('UsersData.txt');
     K := Memo.Lines.Count;
     SetLength(URA, K);
     SplitStrings(',', Memo.Text, SL);
     Memo.Lines.Assign(SL);
     N := Memo.Lines.Count;
     J := 0;
     K := 0;
     for I := 0 to N-1 do
     begin
       case J of
         0:   URA[K].U := Memo.Lines[I];
         1:   URA[K].P := Memo.Lines[I];
         2:   URA[K].Y := Memo.Lines[I];
         3:   URA[K].M := Memo.Lines[I];
         4:   URA[K].D := Memo.Lines[I];
       end;
       if (J<4) then
         Inc(J)
       else
       begin
         J := 0;
         Inc(K);
       end;
     end;
     for I := 0 to K-1 do
     with URA[I] do
     begin
       MemoUsers.Lines.Add(U+';'+P+';'+Y+';'+M+';'+D+';');
     end;
   finally
   end;
end;

end.
0
 
esoftbgCommented:
1).
if (edit1.text = '') or (edit2.Text = '') or (combobox1.Text = '') then
begin
end;

2).
var
  SArr: array of string;
begin
  SetLength(SArr, 32);
end;

3).
Longword      0..4294967295      unsigned 32-bit
Cardinal      0..4294967295      unsigned 32-bit

0
 
bBKCommented:
If the situation happened after you compiled and run your source code. My be Ctrl-F2 to reset and get out of the freezing state.

Otherwise, you need to post all of the available processes on ur computer and cpu their CPU usage here to analyze more. In this case the reasons may be caused by viruses or spyware or other conflict software .......

Regards

******************************
1. The error you got is caused by the operator execute order is not like your thinking. So that, you must add parantheses to make sense.

if (edit1.text = '') or (edit2.Text = '') or (combobox1.Text = '') then
begin
  your-code;
end;

2.
Static array:
VB: Dim astr2(0 To 9) As String
Delphi: Var astr2: array[0..9] of String

Dynamic array:
VB:
   Dim astr2() as String
   Redim astr2(10) --> assign 10 elements to the array
Delphi:
   Var  astr2: array of String;
   Setlength(astr2, 10); --> assign 10 elements

3.  I do not agree with esoftdb about this: Pls check the data type range.
Integer(in VB) =  Smallint(Delphi) with range of:        -32768 to + 32767
Long(in VB) = Integer(Delphi) = Longint(Delphi) with range of: –2147483648..2147483647

4. Your code will give the data to array U only. Because each line correspond to one string, and so that U[x] will get all the line. P[x],D[x],M[x],Y[x] will all blank.
So the best way is used a space between each data in your line instead of comma.
Otherwise, uses TStringList to replace all of the comma by space
Or read line to a string, and then getdata from that String and put to each element in each of your arrays.

If you need code, response back. I will give it to you soon.

Regards.

NBT
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
bBKCommented:
1. The error you got is caused by the operator execute order is not like your thinking. So that, you must add parantheses to make sense.

if (edit1.text = '') or (edit2.Text = '') or (combobox1.Text = '') then
begin
  your-code;
end;

2.
Static array:
VB: Dim astr2(0 To 9) As String
Delphi: Var astr2: array[0..9] of String

Dynamic array:
VB:
   Dim astr2() as String
   Redim astr2(10) --> assign 10 elements to the array
Delphi:
   Var  astr2: array of String;
   Setlength(astr2, 10); --> assign 10 elements

3.  I do not agree with esoftdb about this: Pls check the data type range.
Integer(in VB) =  Smallint(Delphi) with range of:       -32768 to + 32767
Long(in VB) = Integer(Delphi) = Longint(Delphi) with range of: –2147483648..2147483647

4. Your code will give the data to array U only. Because each line correspond to one string, and so that U[x] will get all the line. P[x],D[x],M[x],Y[x] will all blank.
So the best way is used a space between each data in your line instead of comma.
Otherwise, uses TStringList to replace all of the comma by space
Or read line to a string, and then getdata from that String and put to each element in each of your arrays.

If you need code, response back. I will give it to you soon.

Regards.

NBT
0
 
bBKCommented:
Oh, sorry esoftdb. I do not see your last response when posting :)

Regards.
0
 
esoftbgCommented:
I forgot to free dynamically created SL

//........
   finally
     SL.Free;
   end;
0
 
esoftbgCommented:
download a full example about 4).
from:        http://www.geocities.com/esoftbg/
  link:        Q_21188887.zip
0
 
peritoXAuthor Commented:
@esoftbg
can you explain
TRY
Finally

and

TUserRec = record

and the diffrence between putting deleratrations in
type
private
or var (inside the procedure)

and
Assert(Assigned(SS));

If you do I'll give you 50 more points.
You got the first 100.


@bBK
[Q]So the best way is used a space between each data in your line instead of comma.[/Q]
Its doing the same thing.
0
 
esoftbgConnect With a Mentor Commented:
 SL := TStringList.Create; // Dynamicaly created component
  try
    //........ some code
  finally
    SL.Free;                       // Freeing the memory allocated from SL
  end;
The above construction guarantees that SL.Free will be executed no matter of any exception between try .... finally
..................................................................................................................................................................................
type
  TForm1 = class()
    private
      ArrLocal: TArr; // this variable is accessible from all the methods inside the every instance of
    public
      ArrGlobal: TArr; // this variable is accessible from all the Units of the Application (which included this Unit into uses clause)
  end;
procedure TForm1.....
var (inside the procedure)
  Arr: TArr; // this variable is alive only during every execution of this method
begin
//........
end;
....................................................................................................................................................................................TUserRec = record
  //.......................
end;
You need a set of 5 different data about every User :
1. U - name;
2. P - passsword;
3. D - day of registration;
4. M - month of registration;
5. Y - year of registration;
I described all of them as string (different length), but it can be:
type
  TUserRec = record
    U: string[64];
    P: string[128];
    D: Word;
    M: Word;
    Y: Integer;
  end;
After you have this type declared it is very easy to declare a dynamic array so to be possible storing the information for every User:
var
  URA: array of TUserRec;

................................................................................................................................................................................(Delphi's Help) Assert procedure
Tests whether a Boolean expression is true.
Description:
In Delphi code, use Assert as a debugging tool to test that conditions assumed to be true are never violated. Assert provides an opportunity to intercept an unexpected condition and halt a program rather than allow execution to continue under unanticipated conditions.
..................................................................................................................................................................................
0
 
esoftbgCommented:
May be it is better to use:

procedure SplitStrings(Delimiter: Char; S: string; const SS: TStrings);
begin
  if (Assigned(SS)) then
  begin
    SS.Clear;
    SS.DelimitedText := S;
    SS.Delimiter := Delimiter;
  end;
end;

If it is passed a not assigned parameter SS, the procedure will not raise an exception, in this case nothing to be delimited ....
0
 
peritoXAuthor Commented:
Thank You A lot.
0
 
esoftbgCommented:
You are welcome !
Emil
0
All Courses

From novice to tech pro — start learning today.