visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Delphi :: Hex Ascii Highlight


By: DailyGrind U.S.A.  Date: 18/07/2003 00:00:00  English  Points: 500 Status: Answered
Quality : Excellent
Consider the code below[based on code from this site archives] It is a form with 2 x memo 1 x button and an open dialog...
The user opendialogs a file, it reads the file into memo1 as ascii and into memo2 as hex
What I would like to know is if someone could add working code to the program that will enable the user to drag over and highlight any given line from memo1 then what this will do is highlight the corresponding line of data in memo2 or vice versa.I think this is to me an quite difficult so I will award 500 points to a nice solution/modification to the code below.
thank you.
THE CODE
================================================================
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,shellapi;

type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
OpenDialog1: TOpenDialog;
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
FileStream: TFileStream;

public
{ Public declarations }
end;

var
Form1: TForm1;
H: HIcon; //icon global
implementation

{$R *.dfm}
const
MaxBufferSize = 65536; // 64k

type
bytearray = array[0..0] of byte;

procedure TForm1.Button1Click(Sender: TObject);
var
Buffer: Pointer;
BytesRead, i: LongInt;
HexStrTemp, ASCStrTemp: String;

begin
memo1.Lines.Clear;
memo2.Lines.Clear;
if OpenDialog1.Execute then
begin
{simple icon grab routine when file is exe ,dll,ani ,cur,ico}
H := ExtractIcon(Form1.Handle,Pchar
(OpenDialog1.Filename), 0);
Image1.Picture.Icon.Handle := H;
{file stream remainder is to do with hex => ascii}
FileStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead or fmShareDenyNone);
GetMem(Buffer, MaxBufferSize);
try
while FileStream.Position < FileStream.Size do
begin
BytesRead := FileStream.Read(Buffer^, MaxBufferSize);
for i := 1 to BytesRead do
begin
if bytebool(i mod 64) then // items per line
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
end
else
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
HexStrTemp := '';
AscStrTemp := '';
end;
end;
end;
finally
FreeMem(Buffer, MaxBufferSize);
end;
end;
end;




end.
By: VGR Date: 19/07/2003 19:06:00 English  Type : Comment
ok, it works :D

Have fun.

I had to :
1) modify your file reading to accomodate my humble test data (and cope with the case where the last line isn't temrinated by EoLn but by EoF)
2) struggle a bit with TDragObject creation before realizing I could do it without it :D

---code
unit memodrag1;

interface

uses
Windows, Messages, SysUtils, {Variants,} Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,shellapi;

Type TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
OpenDialog1: TOpenDialog;
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure Memo1StartDrag(Sender: TObject; var DragObject: TDragObject);
procedure Memo2DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure Memo2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);

private
{ Private declarations }
FileStream: TFileStream;

public
{ Public declarations }
end;

var
Form1: TForm1;
H: HIcon; //icon global

globline : LongWord; // holds the current selected line

implementation
{$R *.dfm}
const
MaxBufferSize = 65536; // 64k

type
bytearray = array[0..0] of byte;

procedure TForm1.Button1Click(Sender: TObject);
var
Buffer: Pointer;
BytesRead, i: LongInt;
HexStrTemp, ASCStrTemp: String;

begin
memo1.Lines.Clear;
memo2.Lines.Clear;
if OpenDialog1.Execute then
begin
{simple icon grab routine when file is exe ,dll,ani ,cur,ico}
H := ExtractIcon(Form1.Handle,Pchar
(OpenDialog1.Filename), 0);
Image1.Picture.Icon.Handle := H;
{file stream remainder is to do with hex => ascii}
FileStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead or fmShareDenyNone);
GetMem(Buffer, MaxBufferSize);
try
while FileStream.Position < FileStream.Size do
begin
BytesRead := FileStream.Read(Buffer^, MaxBufferSize);
for i := 1 to BytesRead do
begin
if (bytearray(Buffer^)[i-1]<>13) Then // i MOD 64 <>0) Then //bytebool(i mod 64) then // items per line
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
end
else
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
HexStrTemp := '';
AscStrTemp := '';
end;
end;
end;
finally
// last line if not terminated by EoLn
If (bytearray(Buffer^)[i-1]<>13) Then Begin
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
End; // if last line
FreeMem(Buffer, MaxBufferSize);
end;
end;
end;


procedure TForm1.Memo1StartDrag(Sender: TObject;
var DragObject: TDragObject);
Var LineNum : LongInt;
begin
LineNum:=Memo1.Perform(EM_LINEFROMCHAR, Memo1.SelStart, 0);
globline:=LineNum;
end;

procedure TForm1.Memo2DragDrop(Sender, Source: TObject; X, Y: Integer);
Var thepos, i : LongWord;
begin
thepos:=0; // character counter
i:=0; // line counter
while i<globline Do Begin thepos:=thepos+Length(Memo2.Lines); Inc(i); End;
Memo2.SetFocus;
Memo2.SelStart:=thepos;
Memo2.SelLength:=thepos+Length(Memo2.Lines[globline]);
end;

procedure TForm1.Memo2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := True;
end;

procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Memo1.BeginDrag(False,10);
end;

end.
By: VGR Date: 19/07/2003 19:07:00 English  Type : Comment
ah yes, BTW, the dragMode property of Memo1 must be "dmManual"
By: DailyGrind Date: 19/07/2003 20:52:00 English  Type : Comment
Ummm...While I understand you probably put a bit of work into your solution I doesnt do what I asked for. This is what i asked for 'drag over highlight" quote>>
"drag over and highlight any given line from memo1 then what this will do is highlight the corresponding line of data in memo2 or vice versa"
I think you have missunderstood mabye? imagine this text you are reading now click your left mouse btn and drag your cursor to the right.See how it highlights the txt?now if you go back to your modifications of the code that is not happening in the memo1 and it is certainly not highlighting the corresponding data in memo 2.You added a drag drop idea to it which unfortuanatly I do not need to solve my problem.
I thank you for your effort but unfortuanaly i will have to reject your answer.


By: esoftbg Date: 19/07/2003 21:30:00 English  Type : Comment
DailyGrind,
is there any difference between:
MouseMove (just mouse is moved over the Memo whitout pressed button)
and
MouseDragOver (left mouse button down on the Memo and drag without mouse button up)
May be you think about Mouse move but write about MouseDragOver ???

var
I: Integer;
J: Integer;
L: Integer;
M: Integer;
P: Integer;
begin
// If you know Memo1.Lines[3] is highlighted it is very easy to highlight Memo2.Lines[3] // J := 3;
// Here is difficult to find out J=?. If you click on Memo1 it is possible to calculate the position P
L := 1;
P := Memo1.SelStart;
for I := 0 to J-1 do
begin
M := L;
L := L + Length(Memo1.Lines);
if (P>=M) and (P<=L) then
begin
J := I;
Break;
end;
end;
L := 1;
for I := 0 to J-1 do
L := L + Length(Memo2.Lines);
Memo2.SelStart := L;
Memo2.SelLength := Length(Memo2.Lines[J]);
end;

I have no idea if not click on Memo1 ...

emil
By: esoftbg Date: 19/07/2003 21:33:00 English  Type : Comment
oops, the firsrt loop

for I := 0 to J-1 do

must to be

for I := 0 to Memo1.Lines.Count-1 do

emil

By: DailyGrind Date: 19/07/2003 21:43:00 English  Type : Comment
I think you have missunderstood mabye? imagine this text you are reading now click your left mouse btn and drag your cursor to the right.See how it highlights the txt?
============================================================
Consider the code below[based on code from this site archives] It is a form with 2 x memo 1 x button and an open dialog...
The user opendialogs a file, it reads the file into memo1 as ascii and into memo2 as hex
What I would like to know is if someone could add working code to the program that will enable the user to drag over and highlight any given line from memo1 then what this will do is highlight the corresponding line of data in memo2 or vice versa.I think this is to me an quite difficult so I will award 500 points to a nice solution/modification to the code below.
thank you.
THE CODE
================================================================
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,shellapi;

type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
OpenDialog1: TOpenDialog;
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
FileStream: TFileStream;

public
{ Public declarations }
end;

var
Form1: TForm1;
H: HIcon; //icon global
implementation

{$R *.dfm}
const
MaxBufferSize = 65536; // 64k

type
bytearray = array[0..0] of byte;

procedure TForm1.Button1Click(Sender: TObject);
var
Buffer: Pointer;
BytesRead, i: LongInt;
HexStrTemp, ASCStrTemp: String;

begin
memo1.Lines.Clear;
memo2.Lines.Clear;
if OpenDialog1.Execute then
begin
{simple icon grab routine when file is exe ,dll,ani ,cur,ico}
H := ExtractIcon(Form1.Handle,Pchar
(OpenDialog1.Filename), 0);
Image1.Picture.Icon.Handle := H;
{file stream remainder is to do with hex => ascii}
FileStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead or fmShareDenyNone);
GetMem(Buffer, MaxBufferSize);
try
while FileStream.Position < FileStream.Size do
begin
BytesRead := FileStream.Read(Buffer^, MaxBufferSize);
for i := 1 to BytesRead do
begin
if bytebool(i mod 64) then // items per line
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
end
else
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
HexStrTemp := '';
AscStrTemp := '';
end;
end;
end;
finally
FreeMem(Buffer, MaxBufferSize);
end;
end;
end;




end.
By: DragonSlayer Date: 19/07/2003 21:48:00 English  Type : Comment
Hi DailyGrind,

Here's something crude... but doesn't work properly yet:

var
StartCaret, EndCaret: TPoint;

procedure TForm1.BtnOpenClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
MakeHex;
end;
end;

procedure TForm1.MakeHex;
var
i, j: Integer;
s, t: string;
begin
Memo2.Lines.BeginUpdate;
try
Memo2.Lines.Clear;
for i := 0 to Memo1.Lines.Count - 1 do
begin
s := Memo1.Lines;
t := '';
for j := 1 to Length(s) do
t := t + IntToHex(Byte(s[j]), 2) + ' ';
Memo2.Lines.Add(t);
end;
finally
Memo2.Lines.EndUpdate;
end;
end;

procedure TForm1.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i, j: Integer;
Caret1, Caret2: TPoint;
begin
EndCaret := Memo1.CaretPos;

if EndCaret.y > StartCaret.y then
begin
Caret1 := StartCaret;
Caret2 := EndCaret;
end else
begin
if EndCaret.x > StartCaret.x then
begin
Caret1 := StartCaret;
Caret2 := EndCaret;
end else
begin
Caret1 := EndCaret;
Caret2 := StartCaret;
end;
end;

j := 0;
// get characters before selection starts
for i := 0 to Caret1.y do
begin
if i = Caret1.y then
Inc(j, Caret1.x)
else Inc(j, Length(Memo1.Lines));
end;

Memo2.SelStart := j * 3 + (Caret2.y - Caret1.y) * 2 + Caret1.y * 2;
Memo2.SelLength := Memo1.SelLength * 3;
end;

procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
StartCaret := Memo1.CaretPos;
end;


What doesn't work here?

Well, it doesn't work if the selection spans across lines (need to polish up a bit at the formula up there).
also, it doesn't work if the user double-clicks to select instead of click, select, unclick.

Might work on it later... but for now, I'm tired :)



DragonSlayer.
By: DragonSlayer Date: 19/07/2003 22:06:00 English  Type : Comment
try the above code first and tell me if that is something like what you want/need...
By: DragonSlayer Date: 19/07/2003 22:18:00 English  Type : Comment
on second thought... check out these components

<A HREF="http://www.mirkes.de/en/delphi/vcls/hexedit.php">http://www.mirkes.de/en/delphi/vcls/hexedit.php</a>
<A HREF="http://www.torry.net/vcl/edits/other/kelhexeditor.zip">http://www.torry.net/vcl/edits/other/kelhexeditor.zip</a>

especially the first one... the animated gif screenshot (you need to click on the small image first) on that page shows that the component is pretty versatile.


DragonSlayer.
By: DailyGrind Date: 19/07/2003 22:25:00 English  Type : Comment
yeah sure ..
unfortuanatley it is throwing just a few errors. I need something that is working really before I can say If it is what I need.If you have the idea grasped which I think you have and can put a working solution up Im all for it.[while trying to stay as true to the original code as is possible]Thanks for your effort
standing by...
The errors your code produced
===========================================================
[Error] Unit1.pas(38): Undeclared identifier: 'MakeHex'
[Error] Unit1.pas(41): Undeclared identifier: 'MakeHex'
[Error] Unit1.pas(46): Undeclared identifier: 'Memo2'
[Error] Unit1.pas(46): Missing operator or semicolon
[Error] Unit1.pas(48): Missing operator or semicolon
[Error] Unit1.pas(49): Undeclared identifier: 'Memo1'
[Error] Unit1.pas(51): Missing operator or semicolon
[Error] Unit1.pas(55): Missing operator or semicolon
[Error] Unit1.pas(58): Missing operator or semicolon
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
By: DailyGrind Date: 19/07/2003 22:26:00 English  Type : Comment
footnote...
I would like to do this without components thanks for the offer.
By: DragonSlayer Date: 19/07/2003 22:31:00 English  Type : Comment
i was assuming that your Memo (for the text display) component is called Memo1 and the other for the hex display is called Memo2.

also, MakeHex is also given above... just make sure that the declaration also exists in the protected area of your form declaration.
By: VGR Date: 19/07/2003 23:31:00 English  Type : Answer
OK, I modified it so that you're happy with it... Implementing the Drag 'n' Drop from a TMemo's line was A BIG ISSUE. Doing what you wanted was somewhat simplier...

unit memodrag1;

interface

uses
Windows, Messages, SysUtils, {Variants,} Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,shellapi;

Type TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
OpenDialog1: TOpenDialog;
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Memo1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);

private
{ Private declarations }
FileStream: TFileStream;

public
{ Public declarations }
end;

var
Form1: TForm1;
H: HIcon; //icon global

globline : LongWord; // holds the current selected line

implementation
{$R *.dfm}
const
MaxBufferSize = 65536; // 64k

type
bytearray = array[0..0] of byte;

procedure TForm1.Button1Click(Sender: TObject);
var
Buffer: Pointer;
BytesRead, i: LongInt;
HexStrTemp, ASCStrTemp: String;

begin
memo1.Lines.Clear;
memo2.Lines.Clear;
if OpenDialog1.Execute then
begin
{simple icon grab routine when file is exe ,dll,ani ,cur,ico}
H := ExtractIcon(Form1.Handle,Pchar
(OpenDialog1.Filename), 0);
Image1.Picture.Icon.Handle := H;
{file stream remainder is to do with hex => ascii}
FileStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead or fmShareDenyNone);
GetMem(Buffer, MaxBufferSize);
try
while FileStream.Position < FileStream.Size do
begin
BytesRead := FileStream.Read(Buffer^, MaxBufferSize);
for i := 1 to BytesRead do
begin
if (bytearray(Buffer^)[i-1]<>10) Then
if (bytearray(Buffer^)[i-1]<>13) Then // i MOD 64 <>0) Then //bytebool(i mod 64) then // items per line
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
end
else
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
HexStrTemp := '';
AscStrTemp := '';
end;
end;
end;
finally
// last line if not terminated by EoLn
If (bytearray(Buffer^)[i-1]<>13) Then Begin
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
End; // if last line
FreeMem(Buffer, MaxBufferSize);
end;
end;
end;





procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var thepos : LongInt;
LineNum : LongWord;
begin
Memo2.SetFocus;
LineNum:=Memo1.Perform(EM_LINEFROMCHAR, Memo1.SelStart, 0);
thepos:=Memo1.SelStart-2*LineNum;
Memo2.SelStart:=3*thepos+2*LineNum;
Memo1.SetFocus;
end;

procedure TForm1.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Memo2.SetFocus;
Memo2.SelLength:=3*Memo1.SelLength;
end;

end.
By: DailyGrind Date: 19/07/2003 23:59:00 English  Type : Comment
It isnt doing what I want ,Your code runs without error but it doesnt do what I want
quote>> "What I would like to know is if someone could add working code to the program that will enable the user to drag over and highlight any given line from memo1 then what this will do is highlight the corresponding line of data in memo2 or vice versa."
It isnt doing that.
Im sorry that you are trying very hard It will pay off your effort I hope but unless there is something in your code I have missed then it isnt doint what I need{so i cannot award you the points}.I did paste your code into the project in its entirity.Like I said it doesnt error so Im sure I got all your code. Is there a problem understanding the issue? i will now draw a picture using imaginary values for 'eg' sake.

Imaginary Diagram Below
================================================================

OpenFile => imaginaryfile.ini
/ \

memo1 [output] memo2 [output]
| |
DeleteOnCopy 5B 44 65 6C 65 74 65 4F 6E 43 5D 0D
[Owner=Bla] <={user drags mouse over} 5B 44 65 5B 44 65 6C 65 74 65 4F 6E
Personalized=Bl {highlights corresponding data}=> [ 5B 44 65 6C 65]
PersonalizedName=Blah

=================================================================
i appreciate your effort especially in keeping fairly true to the original code
but I need this to higlight corresponding data to work before I can give the points up
thank you
By: VGR Date: 20/07/2003 00:29:00 English  Type : Comment
1) I managed a drag 'n' drop from a selected line from left to right with highlight of the correspoding right file portion
2) I managed to select text from left to right with highlight of the correspoding right file portion
3) I don't understand what you want more.

You can delevop it yourself, you've all the building blocks to do so.
By: VGR Date: 20/07/2003 00:34:00 English  Type : Comment
"What I would like to know is if someone could add working code to the program that will enable the user to drag over and highlight any given line from memo1 then what this will do is highlight the corresponding line of data in memo2 or vice versa"

1) drag over and highlight any given line from memo1 -> selecting text is highlighting it
2) what this will do is highlight the corresponding line of data in memo2 -> done too
By: DailyGrind Date: 20/07/2003 01:11:00 English  Type : Comment
//This is the code taken from my IDE this is your code pasted in
//show me where i have made a mistake and I will gladly award you the points

YOUR CODE BELOW
================================================================

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,shellapi;

type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
OpenDialog1: TOpenDialog;
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);

private
{ Private declarations }
FileStream: TFileStream;

public
{ Public declarations }
end;

var
Form1: TForm1;
H: HIcon; //icon global var
implementation

{$R *.dfm}
const
MaxBufferSize = 65536; // 64k

type
bytearray = array[0..0] of byte;

procedure TForm1.Button1Click(Sender: TObject);
var
Buffer: Pointer;
BytesRead, i: LongInt;
HexStrTemp, ASCStrTemp: String;

begin
memo1.Lines.Clear;
memo2.Lines.Clear;
if OpenDialog1.Execute then
begin
{simple icon grab routine when file is exe ,dll,ani ,cur,ico}
H := ExtractIcon(Form1.Handle,Pchar
(OpenDialog1.Filename), 0);
Image1.Picture.Icon.Handle := H;
{file stream remainder is to do with hex => ascii}
FileStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead or fmShareDenyNone);
GetMem(Buffer, MaxBufferSize);
try
while FileStream.Position < FileStream.Size do
begin
BytesRead := FileStream.Read(Buffer^, MaxBufferSize);
for i := 1 to BytesRead do
begin
if (bytearray(Buffer^)[i-1]<>10) Then
if (bytearray(Buffer^)[i-1]<>13) Then // i MOD 64 <>0) Then //bytebool(i mod 64) then // items per line
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
end
else
begin
HexStrTemp := HexStrTemp + IntToHex(bytearray(Buffer^)[i-1],2) + ' ';
AscStrTemp := AscStrTemp + chr(bytearray(Buffer^)[i-1]);
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
HexStrTemp := '';
AscStrTemp := '';
end;
end;
end;
finally
// last line if not terminated by EoLn
If (bytearray(Buffer^)[i-1]<>13) Then Begin
Memo2.Lines.Add(HexStrTemp);
Memo1.Lines.Add(AscStrTemp);
End; // if last line
FreeMem(Buffer, MaxBufferSize);
end;
end;
end;




procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var thepos : LongInt;
LineNum : LongWord;
begin
Memo2.SetFocus;
LineNum:=Memo1.Perform(EM_LINEFROMCHAR, Memo1.SelStart, 0);
thepos:=Memo1.SelStart-2*LineNum;
Memo2.SelStart:=3*thepos+2*LineNum;
Memo1.SetFocus;
end;


procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Memo2.SetFocus;
Memo2.SelLength:=3*Memo1.SelLength;
end;


end.
By: DragonSlayer Date: 20/07/2003 01:15:00 English  Type : Assist
VGR's code is correct (well, mostly... it still doesn't handle multiple lines correctly)

Anyway, DailyGrind, you copied his (her?) code wrongly... it should be Memo1's MouseUp and MouseDown, not Form1's. I guess you made some similar mistake with my code too? ;)



DragonSlayer.
By: VGR Date: 20/07/2003 01:15:00 English  Type : Comment
My code handles correctly multiple lines, I tested it thoroughly.

regards to all,
By: VGR Date: 20/07/2003 01:28:00 English  Type : Comment
Look at the code : getting the line out of the cursor position in a TMemo isn't a piece of cake, computing positions in both TMemos is just as brilliant as it should be, and originally I built a drag&drop of TMemo line to TMemo which isn't standard at all and required some time to tune.


By: VGR Date: 20/07/2003 02:41:00 English  Type : Comment
yes, except that my second code does what was wanted : you select (highlight) a portion of a line on the memo1, and it is highlighted (selected) in the second.
By: VGR Date: 20/07/2003 02:47:00 English  Type : Comment
as demonstrated in <A HREF="http://www.fecj.org/extra/highlightdemo.html">http://www.fecj.org/extra/highlightdemo.html</a>

Do register to be able to answer

EContact
browser fav
page generated in 500.609870 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page