Title: Get displayed text from an edit box
Question: One of my last problem was 'How to get the displayed text from an edit box' .
All know that Edit.Text return the string . But how can get just the displayed part?
So ... take a look ...
Answer:
I wish to thank to all who share their knowledges .
procedure TForm1.Button1Click(Sender: TObject);
var
FirstChar, LastChar: Integer;
Line: String;
begin
if Edit1.Text '' then
begin
Line := Edit1.Text;
FirstChar := SendMessage(Edit1.Handle, EM_GETFIRSTVISIBLELINE,0,0);
LastChar := SendMessage(Edit1.Handle, EM_CHARFROMPOS, 0, MAKELPARAM(Edit1.ClientRect.Right-3, 7));
Delete(Line, LOWORD(LastChar)+1, Length(Line)+1);
Line := Copy(Line,FirstChar+1,Length(Line)+1);
ShowMessage('First character index is '+IntToStr(FirstChar)+#13+'Last character index is '+IntToStr(LOWORD(LastChar))+#13+'Displayed text is '''+Line+'''');
end else ShowMessage('No text');
end;
end.