Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StringReplace loses SelAttributes

Status
Not open for further replies.

EricDraven

Programmer
Jan 17, 2002
2,999
GB
I have a RichEdit which allows the user to type in text for printing in a letter. This is linked into a table which holds customer records. The user types a letter and where they want a data field in the text (i.e. the field NUMBER), they type */NUMBER/*.

My system uses the StringReplace function to change these entries to their corresponding counterparts in the table. The problem is that the user is allowed to change the font style, color size etc and after completing their formatting, the system looks up all of these fields before printing to change them and the stringreplace procedure loses all of the formatting. Is there a way of storing the SelAttributes so that they can be restored after changing the fields?

Any help greatly appreciated but not with monetary donations as the cupboards are bare and my wallets best before date is circa 1993! Arte Et Labore
 
Well I thought somebody could have helped me out with this one! As it turns out I put my rather small brain to work and figured out a way (using several examples and a bit of guess work) of replacing text (detailed above) in a richedit and keeping its style, color etc when different to the default settings of the richedit. If anybody is actually intrested, you can accomplish it using the following code.

procedure TForm6.ReplaceLetterText(Sender: TObject);
var
Located : LongInt;
StartPos, EndPos : Integer;
begin
with RichEdit1 do
begin
SelStart := 0;
if SelLength <> 0 then StartPos := SelStart + SelLength else
StartPos := 0;
EndPos := Length(Text) - StartPos;
repeat
Located := FindText('*/CUSTNO/*', StartPos, EndPos, [stMatchCase]);
if Located > -1 then
begin
SetFocus;
SelStart := Located;
SelLength := Length('*/CUSTNO/*');
SelText := Table2.FieldByName('CUSTNO').AsString;
end;
until Located = -1;
end;
end; Arte Et Labore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top