Forum > SynEdit
How do you move a Procedure to a separate file
Aruna:
I am uncertain if I should ask this in the General forum category or here. I am using SynEdit so decided to ask here. Apologies if this is not the right place to ask.
I am working on my own text editor after the one I use regularly segfault-ed on me ( Geany ). I have a working unit and I have managed to put together some basic editing functionality. I noticed the code is getting a bit long so decided to move some procedures to their own separate file and call them from Unit1 but I am getting many different errors. The procedure below is one I am trying to move into a separate file. How do you usually do this?
The code below works just fine under Unit1. If I move it to a separate file starts complaining.
--- 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 TForm1.GoToLine;var LineNumber: Integer; InputLine: string; begin // Prompt the user for the line number InputLine := InputBox('Go to Line', 'Enter Line Number:', ''); // Convert the input to an integer if TryStrToInt(InputLine, LineNumber) then begin // Make sure the line number is valid if (LineNumber > 0) and (LineNumber <= SynEdit1.Lines.Count) then begin // Move the caret to the specified line (column 1) SynEdit1.CaretY := LineNumber; SynEdit1.CaretX := 1; // Ensure the caret is visible SynEdit1.EnsureCursorPosVisible; end else ShowMessage('Invalid line number!'); end else ShowMessage('Please enter a valid number.');end;
alpine:
--- Quote ---The code below works just fine under Unit1. If I move it to a separate file starts complaining.
--- End quote ---
Usually the reason for the complaint is shown as text. Proceed accordingly to remove that reason. Or tell us what exactly is the error message.
The given code is a method of TForm1, which includes in its scope the SynEdit1. Moving that code in another file (how exactly?) will take it out from TForm1 scope and SynEdit1 won't be visible. Or may be there is a syntax error at first?
440bx:
@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 ?
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 complaint ?.
summary: a problem is easier to solve when it is known.
Aruna:
--- Quote from: alpine on September 15, 2024, 09:40:15 pm ---
--- Quote ---The code below works just fine under Unit1. If I move it to a separate file starts complaining.
--- End quote ---
Usually the reason for the complaint is shown as text. Proceed accordingly to remove that reason. Or tell us what exactly is the error message.
--- End quote ---
I have attached a screenshot of the errors.
--- Quote from: alpine on September 15, 2024, 09:40:15 pm ---The given code is a method of TForm1, which includes in its scope the SynEdit1. Moving that code in another file (how exactly?) will take it out from TForm1 scope and SynEdit1 won't be visible. Or may be there is a syntax error at first?
--- End quote ---
Yes @alpine your absolutely correct. This is the problem. Once I move my code to another unit SynEdit is out of scope and no longer visible and I have no idea how to pas it along to my procedure file.
Aruna:
--- 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.
Navigation
[0] Message Index
[#] Next page