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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to implement this in my program?

Status
Not open for further replies.

simmo09

Programmer
Apr 22, 2009
82
GB
hi, how can i implement something similar to delphi/lazarus in my program, when you double click a component it auto creates the procedure text, it also assigns the caret inbetween the begin and end tokens.

now no matter what else is typed in the source editor, if you go back and double click that same component delphi/lazarus always seems to know which procedure to go too and set the caret.


can someone pleaseh help me implement something similar?

Thanks!
 
Hi, and welcome to the forum.

You'll need to give us a bit more detail on what you're trying to achieve.

Are you talking about clicking a button on a form in a running program, and modifying a TMemo control or similar in response? We need much more detail regarding your project, and exactly what you want to have happen.
 
hi, thanks for the welcome.

ok, i hope this explains better - say if i had a button and a memo on a form (while it is running), if the button is clicked i can insert some lines into the memo, say for example if i was adding contacts like an address book, but storing it all loose in a memo, clicking the button would add new contact information in the memo.

now say i add another button and double clicked it again, repeat the above and add a new contact information in the same memo - now if like in delphi i went back to the first button and double clicked it, it knows not to create a new contact (in delphi a procedure), but instead by clicking this already assigned button it knows how to find the contact (delphi procedure) and sets the caret to this position.

i hope this makes sense :(

Thank You
 
I think I get it. You want a single TMemo to hold multiple records, and a button to either add a record, or jump to it in the TMemo if it already exists.

For starters - a TMemo is not what you want for this exact example. You would use a TDBGrid and an underlying database. That way you can make use of the dataset methods to add and find records, and make use of primary keys, etc.

However, if your question is primarily about how to jump to a particular position in a TMemo, then you need to ensure you have markers in the TMemo content so that you can identify where each record begins. Access the TMemo content via TMemo.Lines.Text, that way you can set the caret position by setting TMemo.SelStart to the appropriate character position, once you've found your content.

Again - a TMemo is not really ideal, as it's very difficult to ensure record integrity if users can freely modify the contents by typing.

I'm pretty sure that answers your question. Post back if you have any more queries.
 
well, least you understood what i mean :)

TDBGrid sound ok, but then that is a grid, and from what you are saying TMemo is a bad control to use here aswell.

i need the freedom of a text/source editor, but the ability to keep records in that editor.

maybe you could help me set the caret position, i can get it to go to line xx, but i cannot get it to row xx in the memo.

ive tried all kinds of things but its not working:

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Add('line1' + #13#10 + 'line2' + #13#10 + 'with xx do' + #13#10 + 'begin' + #13#10 + ' ' + #13#10 + 'end;' + #13#10);

end;

procedure TForm1.Button2Click(Sender: TObject);
var
i, column: integer;
begin
memo1.SetFocus;
for i:= 0 to memo1.Lines.Count -1 do
begin
With Memo1 do
begin
selstart:= i + 29;
//SendMessage(memo1.Handle, EM_SCROLLCARET, 2, 0);
//SelStart := Perform(EM_LINEINDEX, i -2,0) ;
//sellength:= 2;
//SelStart:= Perform(EM_LINEFROMCHAR, 2, 0) ;
end;
end;
end;

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top