dopors
asked on
Search and Select the Picture inside RxRichEdit
I wanted to select at runtime the image inside a TRxRichEdit
How do i do this?
example:
some data
some data
[image] <-- this will be selected and replace it with something else.
some data
some data
Thanks
How do i do this?
example:
some data
some data
[image] <-- this will be selected and replace it with something else.
some data
some data
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
esoftbg: I can't download it. The link is broke.
Any body how to extract the images inside an RTF Stream. I am using RxRichEdit
Any body how to extract the images inside an RTF Stream. I am using RxRichEdit
The Q_20957296.zip is only 12 Kbytes.It downloads so fast and seems like the link is broke, but it isn't. I just verifyed it.
procedure TForm1.Replace_Rtf_Image(R tf_Name: string);
var
B: Boolean;
I: Integer;
P: Integer;
S: string;
StrList:TStringList;
begin
B := False;
StrList := TStringList.Create;
try
for I := 0 to Memo.Lines.Count-1 do
begin
S := Memo.Lines[I];
P := Pos('\object\objemb{\*\obj class Paint.Picture}', S);
if (B or (P>0)) then
begin
if not B then
begin
B := True;
S := Copy(S, 1, P-1);
StrList.Add(S);
end
else
begin
P := Pos('}}}\par', S);
if (P>0) then
begin
B := False;
Delete(S, P, 2);
P := Pos('\par', S);
if (P>0) then
Delete(S, P, 4);
S := S + 'Here can be inserted new text';
StrList.Add(S);
StrList.Add('\par');
end;
end;
end
else
StrList.Add(Memo.Lines[I]) ;
end;
finally
RichEdit.Clear;
Memo.Lines.Assign(StrList) ;
Memo.Lines.SaveToFile(Rtf_ Name+'_.rt f');
RichEdit.Lines.LoadFromFil e(Rtf_Name +'_.rtf');
StrList.Destroy;
end;
end;
var
B: Boolean;
I: Integer;
P: Integer;
S: string;
StrList:TStringList;
begin
B := False;
StrList := TStringList.Create;
try
for I := 0 to Memo.Lines.Count-1 do
begin
S := Memo.Lines[I];
P := Pos('\object\objemb{\*\obj
if (B or (P>0)) then
begin
if not B then
begin
B := True;
S := Copy(S, 1, P-1);
StrList.Add(S);
end
else
begin
P := Pos('}}}\par', S);
if (P>0) then
begin
B := False;
Delete(S, P, 2);
P := Pos('\par', S);
if (P>0) then
Delete(S, P, 4);
S := S + 'Here can be inserted new text';
StrList.Add(S);
StrList.Add('\par');
end;
end;
end
else
StrList.Add(Memo.Lines[I])
end;
finally
RichEdit.Clear;
Memo.Lines.Assign(StrList)
Memo.Lines.SaveToFile(Rtf_
RichEdit.Lines.LoadFromFil
StrList.Destroy;
end;
end;
Dopors:
I do not program Delphi... I had the same problem with VB.NET... I try to explain how you could do it in Delphi:
> Make a for-loop from n to the length of the box
> in the for-loop: check if this selection is an OBJECT (in stead of text)
> when this is the picture, you should be able to do a replacement
Look at the vb.net code below to see the full idea.
Succes! Daniël
--(here is the VB.NET code; there must be some sort in Delphi!)------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
Dim n As Integer
Dim text As String
For n = 0 To RichTextBox1.TextLength
'Select piece by piece
RichTextBox1.Select(n, 1)
'Check is this an Object
If RichTextBox1.SelectionType = RichTextBoxSelectionTypes. Object Then
RichTextBox1.Cut '<<Cut it out!
End If
Next
-------------------------- ---------- ----------
I do not program Delphi... I had the same problem with VB.NET... I try to explain how you could do it in Delphi:
> Make a for-loop from n to the length of the box
> in the for-loop: check if this selection is an OBJECT (in stead of text)
> when this is the picture, you should be able to do a replacement
Look at the vb.net code below to see the full idea.
Succes! Daniël
--(here is the VB.NET code; there must be some sort in Delphi!)------------------
Dim n As Integer
Dim text As String
For n = 0 To RichTextBox1.TextLength
'Select piece by piece
RichTextBox1.Select(n, 1)
'Check is this an Object
If RichTextBox1.SelectionType
RichTextBox1.Cut '<<Cut it out!
End If
Next
--------------------------
Howevern you can test for selection type
if (stObject in SelectionType) then
SHane