 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
feardotcom Guest
|
Posted: Mon Dec 15, 2003 9:13 am Post subject: Strings in Editboxes |
|
|
I have 10 edit boxes on a form, how do I determine how many of them have
text in them, even tho the user may enter text in box 1 and box 4, the total
should still be only 2 boxes.
I am looking for a simple solution rather than using hundreds of IF
statements.
Thanks in Advance
Louis
|
|
| Back to top |
|
 |
Duncan McNiven Guest
|
Posted: Mon Dec 15, 2003 9:28 am Post subject: Re: Strings in Editboxes |
|
|
On Mon, 15 Dec 2003 11:13:35 +0200, "feardotcom" <feardotnoobz (AT) hayoufellfor (DOT) it> wrote:
| Quote: | I have 10 edit boxes on a form, how do I determine how many of them have
text in them, even tho the user may enter text in box 1 and box 4, the total
should still be only 2 boxes.
|
Somewhere on the form, add code like this:
var
iComp : integer;
Count : Integer;
begin
Count := 0;
for iComp := 0 to Self.ComponentCount - 1 do
if Self.Components[iComp] is TEdit then
if (Self.Components[iComp] as TEdit).Text <> '' then
inc(Count);
--
Duncan
|
|
| Back to top |
|
 |
feardotcom Guest
|
Posted: Mon Dec 15, 2003 12:57 pm Post subject: Re: Strings in Editboxes |
|
|
"Duncan McNiven" <duncan (AT) mcniven (DOT) net> wrote
| Quote: | On Mon, 15 Dec 2003 11:13:35 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
I have 10 edit boxes on a form, how do I determine how many of them have
text in them, even tho the user may enter text in box 1 and box 4, the
total
should still be only 2 boxes.
Somewhere on the form, add code like this:
var
iComp : integer;
Count : Integer;
begin
Count := 0;
for iComp := 0 to Self.ComponentCount - 1 do
if Self.Components[iComp] is TEdit then
if (Self.Components[iComp] as TEdit).Text <> '' then
inc(Count);
--
Duncan
|
mm.. I have some of the boxes that have to be filled with integers/reals,
how do I use this function and implement it then, since not all the boxes
contain text only, I still need to extract the data from them.
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Mon Dec 15, 2003 1:56 pm Post subject: Re: Strings in Editboxes |
|
|
On Mon, 15 Dec 2003 14:57:51 +0200, "feardotcom"
<feardotnoobz (AT) hayoufellfor (DOT) it> wrote:
<snip>
| Quote: |
mm.. I have some of the boxes that have to be filled with integers/reals,
how do I use this function and implement it then, since not all the boxes
contain text only, I still need to extract the data from them.
|
How about making an 'extended' Edit type ?
Also, have you thought about using an Array of Edits ?
|
|
| Back to top |
|
 |
Rob Kennedy Guest
|
Posted: Mon Dec 15, 2003 3:57 pm Post subject: Re: Strings in Editboxes |
|
|
feardotcom wrote:
| Quote: | mm.. I have some of the boxes that have to be filled with integers/reals,
how do I use this function and implement it then, since not all the boxes
contain text only, I still need to extract the data from them.
|
All edit boxes contain text only. If you want to convert that text to
something else later, go ahead, but when you use an edit box, you're
editing text. If the contents are empty, then the Text property will
reflect that, no matter what you intend to do with the contents.
--
Rob
|
|
| Back to top |
|
 |
feardotcom Guest
|
Posted: Mon Dec 15, 2003 4:07 pm Post subject: Re: Strings in Editboxes |
|
|
"J French" <erewhon (AT) nowhere (DOT) com> wrote
| Quote: | On Mon, 15 Dec 2003 14:57:51 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
snip
mm.. I have some of the boxes that have to be filled with integers/reals,
how do I use this function and implement it then, since not all the boxes
contain text only, I still need to extract the data from them.
How about making an 'extended' Edit type ?
Also, have you thought about using an Array of Edits ?
|
Ok, n00b here, I used the gui to add the Edits. I have 10 editboxes that
have to accept text, and 10 that take reals, so that is 20 in total. mmm I
think if I take the IComp Integer I can determine which of the String
editboxes has text, the editbox after that must have a real in it, it will
never be empty. Will try and let you guyz know.
J French, if you can give me an example of what you are talking about, it
would be much apreciated.
TIA
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Mon Dec 15, 2003 5:05 pm Post subject: Re: Strings in Editboxes |
|
|
On Mon, 15 Dec 2003 18:07:40 +0200, "feardotcom"
<feardotnoobz (AT) hayoufellfor (DOT) it> wrote:
| Quote: | "J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:3fddbccd.91227436 (AT) news (DOT) btclick.com...
On Mon, 15 Dec 2003 14:57:51 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
snip
mm.. I have some of the boxes that have to be filled with integers/reals,
how do I use this function and implement it then, since not all the boxes
contain text only, I still need to extract the data from them.
How about making an 'extended' Edit type ?
Also, have you thought about using an Array of Edits ?
Ok, n00b here, I used the gui to add the Edits. I have 10 editboxes that
have to accept text, and 10 that take reals, so that is 20 in total. mmm I
think if I take the IComp Integer I can determine which of the String
editboxes has text, the editbox after that must have a real in it, it will
never be empty. Will try and let you guyz know.
J French, if you can give me an example of what you are talking about, it
would be much apreciated.
|
Here is an example of 'out scoping' the Edit control
- sadly the additional property does not appear in the Design
Properties list
- however I think that you'll get the general idea
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;
Type TEdit = Class( StdCtrls.TEdit )
Private
FInteger: Boolean;
procedure SetInteger(const Value: Boolean);
Published
Property IntegerFlag:Boolean Read FInteger Write SetInteger;
End;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TEdit }
procedure TEdit.SetInteger(const Value: Boolean);
begin
FInteger := Value;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.IntegerFlag := True;
end;
end.
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Mon Dec 15, 2003 6:31 pm Post subject: Re: Strings in Editboxes |
|
|
feardotcom wrote:
| Quote: | "J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:3fddbccd.91227436 (AT) news (DOT) btclick.com...
On Mon, 15 Dec 2003 14:57:51 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
snip
mm.. I have some of the boxes that have to be filled with
integers/reals, how do I use this function and implement it then,
since not all the boxes contain text only, I still need to extract
the data from them.
How about making an 'extended' Edit type ?
Also, have you thought about using an Array of Edits ?
Ok, n00b here, I used the gui to add the Edits. I have 10 editboxes
that have to accept text, and 10 that take reals, so that is 20 in
total
|
Set the ones that take reals tag's to "1" (leave the others at zero), then:
var
iComp : integer;
Count : Integer;
begin
Count := 0;
for iComp := 0 to Self.ComponentCount - 1 do
if (Self.Components[iComp] is TEdit) and
tedit(self.components[icomp]).tag=0 then
if tedit(self.components[icomp]).Text <> '' then
inc(Count);
Gives you the count of edits you use for entering text that have text in
them.
Cheers,
Nicholas Sherlock
|
|
| Back to top |
|
 |
John of Aix Guest
|
Posted: Tue Dec 16, 2003 8:43 am Post subject: Re: Strings in Editboxes |
|
|
"feardotcom" <feardotnoobz (AT) hayoufellfor (DOT) it> a écrit dans le message de
news: brkb2q$2t$1 (AT) ctb-nnrp2 (DOT) saix.net...
| Quote: | "Duncan McNiven" <duncan (AT) mcniven (DOT) net> wrote in message
news:vivqtvg5br1ch75ldjmtif29aulhd4tjsg (AT) 4ax (DOT) com...
On Mon, 15 Dec 2003 11:13:35 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
I have 10 edit boxes on a form, how do I determine how many of
them have
text in them, even tho the user may enter text in box 1 and box
4, the
total
should still be only 2 boxes.
Somewhere on the form, add code like this:
var
iComp : integer;
Count : Integer;
begin
Count := 0;
for iComp := 0 to Self.ComponentCount - 1 do
if Self.Components[iComp] is TEdit then
if (Self.Components[iComp] as TEdit).Text <> '' then
inc(Count);
mm.. I have some of the boxes that have to be filled with
integers/reals,
how do I use this function and implement it then, since not all the
boxes
contain text only, I still need to extract the data from them.
|
try inttostr, floattostr, readthemanual
|
|
| Back to top |
|
 |
feardotcom Guest
|
Posted: Wed Dec 17, 2003 6:27 am Post subject: Re: Strings in Editboxes |
|
|
"Rob Kennedy" <.> wrote
| Quote: | feardotcom wrote:
mm.. I have some of the boxes that have to be filled with
integers/reals,
how do I use this function and implement it then, since not all the
boxes
contain text only, I still need to extract the data from them.
All edit boxes contain text only. If you want to convert that text to
something else later, go ahead, but when you use an edit box, you're
editing text. If the contents are empty, then the Text property will
reflect that, no matter what you intend to do with the contents.
--
Rob
|
Thanks for the reply, I have ways of doing things for the past 8 years. I
have found most of my ways, still relate to the old TP that I used, since I
never was taught delphi, but migrated myself a couple of years ago.
The reason for the 2 rows of edit boxes is the fact that I don't like using
grids and the one row is for descriptions and the second for prices, these
get added as additional text to the generated Invoice.
I was just looking for better ways of doing the things I used to do.
Thanks for the help, I use currtostrf to format the real inputs. A previous
reply was better, thx.
|
|
| Back to top |
|
 |
feardotcom Guest
|
Posted: Wed Dec 17, 2003 6:29 am Post subject: Re: Strings in Editboxes |
|
|
"John of Aix" <j.murphynospam (AT) libertysurf (DOT) fr> wrote
| Quote: |
try inttostr, floattostr, readthemanual
As to your reply, thank you for the effort but the rtfm comment is |
unneccassary.
If you have no scope on the matter, please do not reply.
|
|
| Back to top |
|
 |
feardotcom Guest
|
Posted: Wed Dec 17, 2003 6:31 am Post subject: Re: Strings in Editboxes |
|
|
"J French" <erewhon (AT) nowhere (DOT) com> wrote
| Quote: | On Mon, 15 Dec 2003 18:07:40 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:3fddbccd.91227436 (AT) news (DOT) btclick.com...
On Mon, 15 Dec 2003 14:57:51 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
snip
Here is an example of 'out scoping' the Edit control
- sadly the additional property does not appear in the Design
Properties list
- however I think that you'll get the general idea
snip |
Thank you for the reply, I will look into the matter further, I do think
that the reply from Nicholas would work better by just setting the tag for
the boxes with reals to 1 and then just checking the tags.
|
|
| Back to top |
|
 |
feardotcom Guest
|
Posted: Wed Dec 17, 2003 6:32 am Post subject: Re: Strings in Editboxes |
|
|
"Nicholas Sherlock" <n_sherlock (AT) hotmail (DOT) com> wrote
| Quote: | feardotcom wrote:
"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:3fddbccd.91227436 (AT) news (DOT) btclick.com...
On Mon, 15 Dec 2003 14:57:51 +0200, "feardotcom"
[email]feardotnoobz (AT) hayoufellfor (DOT) it[/email]> wrote:
snip
Set the ones that take reals tag's to "1" (leave the others at zero),
then:
var
iComp : integer;
Count : Integer;
begin
Count := 0;
for iComp := 0 to Self.ComponentCount - 1 do
if (Self.Components[iComp] is TEdit) and
tedit(self.components[icomp]).tag=0 then
if tedit(self.components[icomp]).Text <> '' then
inc(Count);
Gives you the count of edits you use for entering text that have text in
them.
Cheers,
Nicholas Sherlock
Thank your for your reply, |
The solution to my problem was so obvious, but I guess we are sometimes just
to lazy to think, maybe cause it was close to the w/e.
Thanks again
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Wed Dec 17, 2003 1:15 pm Post subject: Re: Strings in Editboxes |
|
|
On Wed, 17 Dec 2003 08:31:03 +0200, "feardotcom"
<feardotnoobz (AT) hayoufellfor (DOT) it> wrote:
<snip>
| Quote: |
snip
Thank you for the reply, I will look into the matter further, I do think
that the reply from Nicholas would work better by just setting the tag for
the boxes with reals to 1 and then just checking the tags.
|
Using the Tag property is one method of 'attaching' 'Flags' or other
things to a Control
It has drawbacks
- the major one being that it is not entirely obvious what is going on
- and unless one gets sneaky the number of Flags is limited
Here is a fairly lengthy demo of using an Array of ones own version of
an Edit control
I've added in a couple of useful things like grabbing the Tab key and
detecting when the Mouse Enters/Exits
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, StdCtrls,
Controls, Forms, Dialogs, Menus;
Type TExEdit = Class( TEdit )
Private
FIntegerFlag: Boolean;
FIndex: Integer;
FWantAllKeysFlag: Boolean;
procedure MouseExit(var Msg: TMessage); message CM_MOUSELEAVE;
procedure MouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message
WM_GETDLGCODE;
Public
Procedure KeyPress(var Key: Char);Override;
Property IntegerFlag:Boolean Read FIntegerFlag Write FIntegerFlag;
Property Index:Integer Read FIndex Write FIndex;
Property WantAllKeysFlag:Boolean Read FWantAllKeysFlag Write
FWantAllKeysFlag;
End;
type
TForm1 = class(TForm)
private
{ Private declarations }
EditAr :Array Of TExEdit;
Label1 :TLabel;
BtnWantAllKeys :TButton;
Procedure EditArChangeEvent( Sender:TObject );
Procedure EditArEnterEvent( Sender:TObject );
procedure EditArKeyDownEvent(Sender: TObject;
var Key: Word; Shift: TShiftState);
procedure EditArKeyPressEvent(Sender: TObject; var Key: Char);
procedure BtnWantAllKeysClick( Sender :TObject );
public
{ Public declarations }
Constructor Create( AOwner :TComponent );Override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TExEdit }
// Numeric Only Entry Permitted
procedure TExEdit.KeyPress(var Key: Char);
begin
If FIntegerFlag Then
If Pos( Key, '0123456789'#8#9#13 ) = 0 Then
Begin
Key := #0;
Beep;
End;
Inherited; //Essential
end;
// Mouse moves over Editbox
procedure TExEdit.MouseEnter(var Msg: TMessage);
begin
// Very bad style - dirty in extreme
Form1.Label1.Caption := 'Mouse Enter '
+ IntToStr(FIndex);
Inherited;
end;
// Mouse leaves Editbox
procedure TExEdit.MouseExit(var Msg: TMessage);
begin
// Very bad style
Form1.Label1.Caption := 'Mouse Exit '
+ IntToStr(FIndex);
Inherited;
end;
// This allows you to grab Tab Keys etc
procedure TExEdit.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
If FWantAllKeysFlag Then
Msg.Result := DLGC_WANTARROWS
or DLGC_WANTTAB
or DLGC_WANTALLKEYS
Else
Inherited;
end;
{ TForm1 }
constructor TForm1.Create(AOwner: TComponent);
Var
L9, V, H, D, Max :Integer;
begin
Inherited;
Max := 8; // Eight Boxes
V := 15;
H := 20;
D := 20;
SetLength( EditAr, Max );
For L9 := Low( EditAr ) To High( EditAr ) Do
Begin
EditAr[L9] := TExEdit.Create( Self );
EditAr[L9].Parent := Self; // Essential
EditAr[L9].Top := V;
EditAr[L9].Left := H;
EditAr[L9].Name := 'EditAr' + IntToStr(L9) ;
EditAr[L9].Index := L9;
EditAr[L9].OnChange := EditArChangeEvent;
EditAr[L9].OnEnter := EditArEnterEvent;
EditAr[L9].OnKeyDown := EditArKeyDownEvent;
EditAr[L9].OnKeyPress := EditArKeyPressEvent;
V := V + D;
// Odd Numbers Contain Integers
If (L9 And 1) = 1 Then
Begin
EditAr[L9].IntegerFlag := True;
EditAr[L9].Text := IntToStr(L9);
End;
// Play with this - Useful
EditAr[L9].WantAllKeysFlag := False;
End;
// Create Label1
Label1 := TLabel.Create( Self );
Label1.Parent := Self;
Label1.Top := V + D;
Label1.Left := H;
Label1.Visible := True;
Label1.Font.Color := clRed;
// Create BtnWantAllKeys
BtnWantAllKeys := TButton.Create(Self);
BtnWantAllKeys.Parent := Self;
BtnWantAllKeys.SetBounds(150, 30, 130, 60);
BtnWantAllKeys.Caption := 'Toggle WantAllKeys';
BtnWantAllKeys.OnClick := BtnWantAllKeysClick;
end;
// Toggle Grabbing Tab Keys
procedure TForm1.BtnWantAllKeysClick(Sender: TObject);
Var
L9 :Integer;
S :String;
begin
// Toggle
For L9 := Low(EditAr) To High(EditAr) Do
EditAr[L9].WantAllKeysFlag := Not EditAr[L9].WantAllKeysFlag;
EditAr[0].SetFocus;
// Caption
Case EditAr[0].WantAllKeysFlag Of
True : S := ' OFF';
False: S := ' ON';
End;
BtnWantAllKeys.Caption := 'Turn WantAllKeys' + S;
end;
// Change Event for Edit Control
// Demonstrate use as pure Typed Control
procedure TForm1.EditArChangeEvent(Sender: TObject);
Var
EB :TExEdit;
begin
EB := (Sender As TExEdit); // Error if problem
Self.Caption := 'Change in EditAr ' + IntToStr(EB.Index);
end;
// Enter Focus Event for Edit Control
// Demonstrate use as part of Array
procedure TForm1.EditArEnterEvent(Sender: TObject);
Var
I :Integer;
S :String;
begin
I := (Sender As TExEdit).Index; // Error if problem
S := 'Working on EditAr ' + IntToStr( I );
S := S + ' (Text is: ' + EditAr[I].Text + ')';
If EditAr[I].IntegerFlag Then
S := S + ' - Entry MUST be Integer';
Self.Caption := S;
end;
// KeyDown Event - Show trapping of Tab Key
procedure TForm1.EditArKeyDownEvent(Sender: TObject; var Key: Word;
Shift: TShiftState);
Var
S :String;
begin
S := IntToStr( Key ) + ' ';
S := S + ShortCutToText( Key ) + StringOfChar(#32,15);
Canvas.TextOut(50,0, Copy( S, 1, 15));
end;
// KeyPress Event - Show Tab Key Trap
// Also use of the Array of TExEdits
procedure TForm1.EditArKeyPressEvent(Sender: TObject; var Key: Char);
Var
I :Integer;
begin
Canvas.TextOut(0,0,IntToStr(Ord(Key)) + ' ' );
If (Key = #13) Or (Key = #9) Then
Begin
Key := #0;
I := (Sender As TExEdit).Index;
I := I + 1;
If I > High(EditAr) Then
I := Low(EditAr);
EditAr[ I ].SetFocus;
End;
end;
end.
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Wed Dec 17, 2003 5:55 pm Post subject: Re: Strings in Editboxes |
|
|
"feardotcom" <feardotnoobz (AT) hayoufellfor (DOT) it> wrote
| Quote: | The reason for the 2 rows of edit boxes is the fact that I don't like
using
grids and the one row is for descriptions and the second for prices, these
get added as additional text to the generated Invoice.
I was just looking for better ways of doing the things I used to do.
|
Then use a tStringGrid.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|