Forum > SynEdit
How do you move a Procedure to a separate file
dsiders:
--- Quote from: Aruna on September 15, 2024, 10:22:44 pm ---
--- Quote from: 440bx on September 15, 2024, 09:43:57 pm ---@alpine already alluded to what I'm going to ask, which is, when you say "separate file", do you mean a separate unit or an include file ?
--- End quote ---
Forgive me for not being specific. I am moving code from Unit1 to new Unit3. Hope that makes things clearer
--- Quote from: 440bx on September 15, 2024, 09:43:57 pm ---That makes a big difference.
Also, as @alpine alluded to, just stating the compiler is complaining isn't very helpful. What is the textual compiler complain.
summary: a problem is easier to solve when it is known.
--- End quote ---
I attached a screenshot showing the errors in my reply to to @alpines.
--- End quote ---
The object inspector shows the TSynEdit instance is named SynEdit1, SynEdit <> SynEdit1.
Sieben:
You need to precede the name of the instance of your TSynEdit - SynEdit1 - with the the name of the instance of your TForm1. Assuming that TForm1 is your main form and that it will be created automatically that would be Form1. Unit1 has to be in the uses of Unit3 to make this reference possible.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Form1.SynEdit1
Another and more generic way of doing that would be to pass the instance of TSynEdit as a parameter to your GoToLine method.
And, if I may give some advice, rename your units, forms and every other component you use to sth that tells you what that entity is about. Once your project grows or you want to handle a couple of them you will realize how much time it saves.
Aruna:
--- Quote from: dsiders on September 15, 2024, 10:39:21 pm ---The object inspector shows the TSynEdit instance is named SynEdit1, SynEdit <> SynEdit1.
--- End quote ---
I manged to get things working. Thank you @dsiders.
The zip has the source code. If anyone wants to fiddle with it.
So far I can open a file, make changes, then save the file. Edit menu option yet to be coded. Search menu option 'goto line' works the others not yet. The window menu option has a Vertical Split and a Horizontal split. Both work but I am yet learning how to correctly use this. Can use some help. It will open two files no problem. I do not how to save each one yet.
The status bar will show you the full path of the file currently being worked on. Current row and rowcount. Cursor Column position. Date and Time ( real-time clock)
All critiques and suggestions are welcome. Any feedback is very much appreciated. Thanks.
What I did to get things working is File-->New Unit then plugged in my gotoline procedure but had to declare it like this:.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure GoToLine(SynEdit: TSynEdit);
Then in the main Unit1 in the uses section plugged in unit3 and called teh procedure like this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- GoToLine(SynEdit1); Done!
EDIT: Sorry, forgot to attach the zip. It is there now.
edit2: added the *.lpi file
Aruna:
--- Quote from: Sieben on September 15, 2024, 10:50:54 pm ---You need to precede the name of the instance of your TSynEdit - SynEdit1 - with the the name of the instance of your TForm1. Assuming that TForm1 is your main form and that it will be created automatically that would be Form1. Unit1 has to be in the uses of Unit3 to make this reference possible.
--- End quote ---
When I was experimenting I did this and it said something about a 'circular reference'
--- Quote from: Sieben on September 15, 2024, 10:50:54 pm ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Form1.SynEdit1
Another and more generic way of doing that would be to pass the instance of TSynEdit as a parameter to your GoToLine method.
--- End quote ---
Yes this is what I did. I am still very new to this object oriented stuff.
--- Quote from: Sieben on September 15, 2024, 10:50:54 pm ---And, if I may give some advice, rename your units, forms and every other component you use to sth that tells you what that entity is about. Once your project grows or you want to handle a couple of them you will realize how much time it saves.
--- End quote ---
Thank you for the advice @Sieben I will try to do so.
Sieben:
--- Quote ---When I was experimenting I did this and it said something about a 'circular reference
--- End quote ---
Sorry, I forgot to mention that it should be the uses list of the implementation section.
Navigation
[0] Message Index
[#] Next page
[*] Previous page