Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Some Newbie Questions

Posted on 2004-10-30
13
Medium Priority
?
196 Views
Last Modified: 2010-04-05
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???
0
Comment
Question by:peritoX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
  • +1
13 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 12453297
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
 
LVL 12

Accepted Solution

by:
esoftbg earned 600 total points
ID: 12453561
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
 

Expert Comment

by:bBK
ID: 12453574
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:bBK
ID: 12453581
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
 

Expert Comment

by:bBK
ID: 12453582
Oh, sorry esoftdb. I do not see your last response when posting :)

Regards.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12453593
I forgot to free dynamically created SL

//........
   finally
     SL.Free;
   end;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12455924
download a full example about 4).
from:        http://www.geocities.com/esoftbg/
  link:        Q_21188887.zip
0
 

Author Comment

by:peritoX
ID: 12457974
@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
 
LVL 12

Assisted Solution

by:esoftbg
esoftbg earned 600 total points
ID: 12458294
 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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12458667
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
 

Author Comment

by:peritoX
ID: 12461978
Thank You A lot.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12461996
You are welcome !
Emil
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question