Solved

How to replace these numbers with text from edits and memos? (for Delphized?;)

Posted on 2004-03-28
30
232 Views
Last Modified: 2010-04-05
Hi all!! I'd like to replace the numbers below, with text from edits and memos. For instance > the text ${1} should refer to the text from Edit1. The text ${3} should refer to the text from memo1.

So in the end I should be able to replace all the ${number}s with the text from edit1; edit2; memo1; memo2 and so on....Replacing one  is no problem. But how do I get my app to replace the numbers 1 to 20 silently without a dialog and preferrably by swapping from activepage 1 to activepage 4 of a pagecontrol, while maintaining the 'formatting' as shown below?????????? (and now you're busy anyway;) > is there a way to hide the ${number}s from showing up in the memo at run time but still have them replaced???

Name:...............:${1}
Last Name:........:${2}
Comment:.........:${3}

Tnx in advance!!

Peter

Ps a working sample equals the reward...well ofcourse......
0
Comment
Question by:PeterdeB
[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
  • 16
  • 9
  • 5
30 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10700567
You better come up with a better solution for explaining what you want done, you have me lost!

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10700579
You have a Tedit & TMemo on each of the 20 pages of a TPageControl?

You want to replace ${1} - ${20} with the text of the controls from the PageCOntrol?

 I have no clue what you want, im just babbling on......

Shane

0
 

Author Comment

by:PeterdeB
ID: 10700647
Oh ok sorry I apologize > I have say 5 pages from a TPagecontrol and each of them hols let's say 3 edits and 1 memo. On my last page I have 1 memo which loaded a template file containing all the numbers that should be replaced by the text of the several components from all of the other pages........(so what you guess > 'You want to replace.....' = RIGHT!!;)

Peter
0
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!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10700684
You still did not describe it properly. You leave way too many open questions.

 Use alittle white space and describe.

Questions:

1.) The numbers in the template memo, will those be the only numbers in the memo?

2.) Will each memo have the exact number of components? i.e. 3 edits and 1 memo

3.)  Will there be a set number of pages in the notebook? i.e. 5

4.) Does a number in the template memo correspond with a Edit box or TMemo (either or)?

5.) Do you have your controls numbered in anyway (i.e. tag property, name (example: Edit1, memo1)

etc, ect, ect.

These are all valid questions....

<Smile>

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10700724
if the controls are numbered using the tag property

 then something like

function GetControlText(ID: Integer): String
begin
 for I:= 0 to Form1.ControlCount - 1 do
  if Form1.Controls[I] is TCustomControl then
   if TCustomControl(Form1.Controls[I]).tag = ID then
   result:= TCustomControl(Form1.Controls[I]).Text;
end;

if the numbers of the controls are the only numbers in the template memo, then
something like (kinda pseudo code off the top of my head), but you should get the picture



For I:= 0 to Memo1.Lines.Count - 1 do
begin
 for J:= 0 to Length(Memo1.Lines[I]) - 1 do
  if Memo1.Lines[I][J] in ['1','2','3','4','5','6','7','8','9'] then
   Memo1.Lines[I].Insert(GetControlText(StrToInt(Memo1.Lines[I][J])),J);
end;


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10700729
do you have the source code you can zip up and email me, i'ff take a look...

holmesshane AT charter DOT net

Shane
0
 

Author Comment

by:PeterdeB
ID: 10700769
Okay my friend.........

1.) No there will be more numbers (coming from input etc.)
2.) No, but I figured that if you'd show me how to implement this thing using 3 edits and 1 memo > I would be able to   implement this thing with any number of components > ofcourse then my question wasn't quite appropriate cause you could never provide a working sample without me telling which components I stuffed where......my apologize....)
3.) Yes > 5 pages max
4.) Some numbers correspond to editboxes some to comboboxes and some to memos
5.) No, should I ? (Guess so otherwise you wouldn't have asked me so > I could tag all of the controls (that is if tagging means setting its tagproperty to a unique number)

> I will be using 2 memos;  7 Spinedits; 6 Comboboxes; (so 20 should be 15 to be precise)

> memo1 + 5 spinedits reside on page1 of the pagecontrol
> 6 comboboxes + 2 spinedits reside on the second page of the pagecontrol
> memo2 resides on the third page of the pagecontrol
memo3 resides on page 5 and is the one which loaded the template file........this is what the template file looks like:

 *******************************************************************************
 Wachtrapport van de...........:${0}
 
 ${1}
 
 Aandachtspunten Planning........:${2}
 
 
--------------------------------------------------------------------------------------------------------
 Gevonden waarden bij analyseren
 -------------------------------------------------------------------------------------------------------
 Groffosfaatbad 1 Puntensterkte: ${3}  
 Ijzergehalte:..............................: ${4}
 Groffosfaatbad 2 Puntensterkte: ${5}  
 Ijzergehalte:..............................: ${6}
 Ultra Tech          Puntensterkte.: ${7}
 -------------------------------------------------------------------------------------------------------
 Stand van zaken mbt waterzuivering:
 -------------------------------------------------------------------------------------------------------
 Standreactor.............................:${8}
 Indikker:....................................:${9}
 Grote pers:................................:${10}
 Kleine pers:...............................:${11}
-------------------------------------------------------------------------------------------------------
 Gevonden waarden bij analyseren:
 ------------------------------------------------------------------------------------------------------
 Zink waarde afvalwater:..........:${12}
 Tin waarde afvalwater:............:${13}
 ------------------------------------------------------------------------------------------------------
 Ook belangrijk!:
--------------------------------------------------------------------------------------------------------
 Stofzak vervangen:..................:${14}
 Vuilnisbak geleegd:..................:${15}
 Afdekballen overgeschept:......:${16}
 Contactplaatjes gereinigd:........:${17}
 Asbakken geleegd:..................:${18}
 -------------------------------------------------------------------------------------------------------
 Algemene aandachtspunten:....:${19}

( the few numbers I didn't mention involve checkboxes or radiobuttons > like >

  if radiobutton1.checked then
 replacetext:= 'vroege dienst' else
replacetext:= 'late dienst';

> coming from this procedure:

procedure TfrmMain.btnReplaceClick(Sender: TObject);
var selpos:integer;
findtext: string;
begin
findtext:= '${0}';

 SelPos := Pos(FindText, MmoVoorbeeld.Lines.Text);
    if SelPos > 0 then
    begin
      MmoVoorbeeld.SelStart := SelPos - 1;
      MmoVoorbeeld.SelLength := Length(FindText);
      { Replace selected text with ReplaceText }
      MmoVoorbeeld.SelText := ReplaceText;
    end
    else MessageDlg(Concat('Check findtext!!'), mtError, [mbOk], 0);
  end;

Lemme know if there's something more you should know okay?

My regards and tnx in advance for all your effords!

Peter
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10700787
OK, thanks, i'll see what i can come up with!
0
 

Author Comment

by:PeterdeB
ID: 10700838
Thanks in advance!!

Peter
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10701381
OK, dont forget to tag all your controls 0 - whatever


procedure TForm1.Button1Click(Sender: TObject);
var
 I,J, K, Id, IdPos: Integer;
 tmpStr: String;
begin
 for I:= 0 to PageControl1.PageCount - 1 do
 begin
  for J:= 0 to TTabSheet(PageControl1.Pages[I]).ControlCount - 1 do
  if TTabSheet(PageControl1.Pages[I]).Controls[J] is TCustomEdit then
  begin
   Id:= TCustomEdit(TTabSheet(PageControl1.Pages[I]).Controls[J]).Tag;
   memTemplate.Lines.BeginUpdate;
    for K:= 1 to Length(memTemplate.Text) do
     if memTemplate.Text[K] = intToStr(Id) then
     begin
      tmpStr:= memTemplate.Text;
      Delete(tmpStr, K , 1);
      Insert(TCustomEdit(TTabSheet(PageControl1.Pages[I]).Controls[J]).Text,
            tmpStr, K);
      memTemplate.Text:= tmpStr;
     end;
    memTemplate.Lines.EndUpdate;
   end;
  end;
 end;
end.

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10701392
I have a sample app zipped up and ready for you, if you want it?

Shane
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10705247
Hi Shane and Peterde :)
Just to support with my idea....
What about naming your controls as your numbered consts in the templates?

Then i'd do:

var
cmp: TComponent;
i: Integer;
begin
for i := 0 to 19 do begin //0 to 19 bcz i saw this range in the template
  cmp := FindComponent('{'+inttostr(i)+'});
 if Assigned(cmp) then
    StringReplace(memTemplate.text,cmp.name,TCustomEdit(cmp).Text);
   end;
end;

It seems the less coded method i think.....

f68 ;-)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10705255
ah...missed the $ :)

cmp := FindComponent('${'+inttostr(i)+'});
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10705752
Hi Ferruccio,!

1.) Can you name a component  starting with an Identifier? Such as '$' or '{'?

2.) Will StringReplace allow you to perform on the const memTemplate.text, or do you have to place it in a variable first, peform the replace and put it back?

<?>

Shane
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10705906
well Shane you're right for the 1st one....(i was thinking just from head....)
The only non standard character allowed in the name is the underscore....
so we can use names as _0_, _1_ etc

then
cmp := FindComponent('_'+inttostr(i)+'_');
 if Assigned(cmp) then
    memTemplate.text := StringReplace(memTemplate.text,'${+IntToStr(i)+'}',TCustomEdit(cmp).Text);
   end;
the 2nd: yes it's possible, as you can see above
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10705933
Just keeping ya on your toes.....

<smile>

memTemplate.text := StringReplace(memTemplate.text,'${+IntToStr(i)+'}',TCustomEdit(cmp).Text);

<smile>


Shane
0
 

Author Comment

by:PeterdeB
ID: 10706849
Wow guys!!! > I just got back from work and several other issues and didn't really expect such enthousiasm > Ferrucio and Shane > this will take me some time to 'absorb' all you wrote ofcourse......thanks in advance > I'm firing up Delphi and will get back to you guys as soon as I have something useful to state;) Thanks thanks thanks thanks in advance!! (I REALLY appreciate all the effords you put into it!!)

Peter;))
0
 

Author Comment

by:PeterdeB
ID: 10707014
Oh yes and Shane > please do send your zipped app my way!!

Regards and greatest respect,

Peter

(the refreshing of EE's pages seems somewhat unpredictable > after every refresh I get some articles extra > not all at once like I thought and expected)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10707047
um, i would need an email address

shane
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10707186
here his email shane...
f dot vanbommel1 at chello dot nl
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10707222
Thanks!

Shane
0
 

Author Comment

by:PeterdeB
ID: 10707271
Thanks Ferruccio!!;)

I can't seem to get it working > because of the TReplaceFlags > and it doesn't do without it......Could one of you guys shed some light upon this darkness to be Replaced?

>> here's where I am

StringReplace(mmoVoorbeeld.text,cmp.name,TCustomEdit(cmp).Text, ?????????  < and that's where I'm stuck.....

Regards Peter
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10707311
oh god sorry...it should be
StringReplace(mmoVoorbeeld.text,cmp.name,TCustomEdit(cmp).Text,[])

but you can also use these flags
rfReplaceAll
      Replace all occurrences. If this flag is not present, only the first occurrence of the target substring is replaced.
rfIgnoreCase
      Match occurrences of the substring case-insensitively. If this flag is not present, only case-sensitive matches are considered.

so in your case the better is
StringReplace(mmoVoorbeeld.text,cmp.name,TCustomEdit(cmp).Text,[])
or
StringReplace(mmoVoorbeeld.text,cmp.name,TCustomEdit(cmp).Text,[rfIgnoreCase])
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10707336
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;

lace an empty set there []

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 500 total points
ID: 10707375
PeterdeB, Did you receive the solution i emailed you?

Shane
0
 

Author Comment

by:PeterdeB
ID: 10707400
Hi Shane > no I did not > I suppose you didn't get what I sent you this morning either?

Hang on > will check again right away.........Peter

(and thanks Ferruccio + Shane > for the Treplaceflags thing;)
0
 

Author Comment

by:PeterdeB
ID: 10707406
Yesssssssssssssss GOT IT!!;)

Peter
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10707526
Well, no matter, it was the same thing I posted earlier above

procedure TForm1.Button1Click(Sender: TObject);
var
 I,J, K, Id, IdPos: Integer;
 tmpStr: String;
begin
 for I:= 0 to PageControl1.PageCount - 1 do
 begin
  for J:= 0 to TTabSheet(PageControl1.Pages[I]).ControlCount - 1 do
  if TTabSheet(PageControl1.Pages[I]).Controls[J] is TCustomEdit then
  begin
   Id:= TCustomEdit(TTabSheet(PageControl1.Pages[I]).Controls[J]).Tag;
   memTemplate.Lines.BeginUpdate;
    for K:= 1 to Length(memTemplate.Text) do
     if memTemplate.Text[K] = intToStr(Id) then
     begin
      tmpStr:= memTemplate.Text;
      Delete(tmpStr, K , 1);
      Insert(TCustomEdit(TTabSheet(PageControl1.Pages[I]).Controls[J]).Text,
            tmpStr, K);
      memTemplate.Text:= tmpStr;
     end;
    memTemplate.Lines.EndUpdate;
   end;
  end;
 end;
end.



Shane
0
 

Author Comment

by:PeterdeB
ID: 10707769
Well yes matter;) > Perfect!! Works like h*ll!! (and from my point of view h*ll works, just to avoid misunderstanding > you get the points Shane!!)

Thanks and thanks again........thanks Ferruccio too..........both my regards and respect!

Peter;)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10707803
Cheers!

Shane
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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 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