[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

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

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
PeterdeB
Asked:
PeterdeB
  • 16
  • 9
  • 5
1 Solution
 
shaneholmesCommented:
You better come up with a better solution for explaining what you want done, you have me lost!

Shane
0
 
shaneholmesCommented:
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
 
PeterdeBAuthor Commented:
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
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
shaneholmesCommented:
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
 
shaneholmesCommented:
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
 
shaneholmesCommented:
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
 
PeterdeBAuthor Commented:
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
 
shaneholmesCommented:
OK, thanks, i'll see what i can come up with!
0
 
PeterdeBAuthor Commented:
Thanks in advance!!

Peter
0
 
shaneholmesCommented:
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
 
shaneholmesCommented:
I have a sample app zipped up and ready for you, if you want it?

Shane
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
ah...missed the $ :)

cmp := FindComponent('${'+inttostr(i)+'});
0
 
shaneholmesCommented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
shaneholmesCommented:
Just keeping ya on your toes.....

<smile>

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

<smile>


Shane
0
 
PeterdeBAuthor Commented:
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
 
PeterdeBAuthor Commented:
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
 
shaneholmesCommented:
um, i would need an email address

shane
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
here his email shane...
f dot vanbommel1 at chello dot nl
0
 
shaneholmesCommented:
Thanks!

Shane
0
 
PeterdeBAuthor Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
shaneholmesCommented:
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;

lace an empty set there []

Shane
0
 
shaneholmesCommented:
PeterdeB, Did you receive the solution i emailed you?

Shane
0
 
PeterdeBAuthor Commented:
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
 
PeterdeBAuthor Commented:
Yesssssssssssssss GOT IT!!;)

Peter
0
 
shaneholmesCommented:
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
 
PeterdeBAuthor Commented:
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
 
shaneholmesCommented:
Cheers!

Shane
0

Featured Post

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.

  • 16
  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now