Recent

Author Topic: compiling code programmatically  (Read 2055 times)

Ildus03

  • New member
  • *
  • Posts: 7
compiling code programmatically
« on: June 24, 2019, 12:58:53 pm »
Need from TSynEdit or file .pas compile the application using the built-in Lazarus or FPC compiler.
Q: what class or component to use and how to implement all this?
 I accept any interesting and working ideas ;)

In Russian:
Нужно из TSynEdit или файл .pas скомпилировать приложение, используя встроенный компилятор Lazarus или FPC.
Вопрос: какой класс или компонент использовать и как реализовать все это?
Принимаю любые интересные и рабочие идеи
« Last Edit: June 24, 2019, 02:58:43 pm by Ildus03 »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: compiling code programmatically
« Reply #1 on: June 24, 2019, 02:31:42 pm »
Maybe explain more verbose? More details? Example?

Also, if this is "google translation", then add the "original language text" below the English translation, and maybe someone else can help with the translation. (But always include the English part)

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: compiling code programmatically
« Reply #2 on: June 24, 2019, 02:56:25 pm »
TprocessAsync comes to mind.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: compiling code programmatically
« Reply #3 on: June 24, 2019, 03:08:54 pm »
In Russian:
Нужно из TSynEdit или файл .pas скомпилировать приложение, используя встроенный компилятор Lazarus или FPC.
Вопрос: какой класс или компонент использовать и как реализовать все это?
Принимаю любые интересные и рабочие идеи
"встроенного компилятора" Lazarus или FPC не существует.
Есть или сам FPC - и его придёться вызвать как внешнее приложение (например через TProcess)
Или PascalScript. Но PascalScript это не FPC, и у него есть свои ограничения.

Ildus03

  • New member
  • *
  • Posts: 7
Re: compiling code programmatically
« Reply #4 on: June 27, 2019, 09:04:59 pm »
I decided to use lazbuild it is very convenient, you only need to specify the path to the project file.
Maybe someone will come in handy.
Code: Pascal  [Select][+][-]
  1. SysUtils.ExecuteProcess('E:\Lazarus\CGC (WinRar)\Test\lazbuild.exe', path to the project file .lpi);

It is necessary that the program would lazbuild was in the folder with the project or above it on the branch.
-----------------------------------------------------------------------------------------------------------------------
In Russian:

Я решил использовать lazbuild это очень удобно, нужно лишь указать путь к файлу проекта.
Может кому-нибудь и пригодится.
Code: Pascal  [Select][+][-]
  1. SysUtils.ExecuteProcess('E:\Lazarus\CGC (Уйнарер)\Test\lazbuild.exe', путь к файлу проекта .lpi);

При этом нужно, что бы программа lazbuild была в папке с проектом или выше ее по ветви.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: compiling code programmatically
« Reply #5 on: June 28, 2019, 06:15:22 am »
Если будешь распростанять свою программу, не забывай, что lazbuild-у необходим настроенный Lazarus. И настроенный fpc вместе с ним.

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: compiling code programmatically
« Reply #6 on: June 28, 2019, 10:35:20 am »
There is another option: the way fp (the text mode ide) compiles in the compiler....
That can also be done with a an editor written using synedit...... single executable... no dependencies....
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Ildus03

  • New member
  • *
  • Posts: 7
Re: compiling code programmatically
« Reply #7 on: June 28, 2019, 08:53:05 pm »
There is another option: the way fp (the text mode ide) compiles in the compiler....
That can also be done with a an editor written using synedit...... single executable... no dependencies....
Can be on much detail?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: compiling code programmatically
« Reply #8 on: June 28, 2019, 09:28:29 pm »
Very basically, fp incorporates the compiler inside itself. That is, it uses an internal compiler instead of the external one.

The source code of fp shows how that is done and it's quite instructive.

Google-translated:

По сути, fp включает в себя компилятор. То есть он использует внутренний компилятор вместо внешнего.

Исходный код fp показывает, как это делается, и это довольно поучительно.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: compiling code programmatically
« Reply #9 on: June 28, 2019, 09:38:16 pm »
Indeed, and it is indeed quite instructive!!
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Ildus03

  • New member
  • *
  • Posts: 7
Re: compiling code programmatically
« Reply #10 on: June 29, 2019, 07:27:22 pm »
Very basically, fp incorporates the compiler inside itself. That is, it uses an internal compiler instead of the external one.

Unfortunately, there is one problem, fp can only compile extension files .pas or .pp

https://www.freepascal.org/docs-html/current/user/userse10.html#x26-330003.2

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: compiling code programmatically
« Reply #11 on: June 29, 2019, 08:18:14 pm »
Very basically, fp incorporates the compiler inside itself. That is, it uses an internal compiler instead of the external one.

Unfortunately, there is one problem, fp can only compile extension files .pas or .pp

https://www.freepascal.org/docs-html/current/user/userse10.html#x26-330003.2

That page talks about fpc (the command-line compiler) not fp (the text-mode IDE) and all it says is that if your source ends in .pas or .pp you can omit the extension in the invocation. If it's not, if for example it is .lpr, you must use the full name+extension, i.e. you must call it like "fpc myprogram.lpr" instead of just "fpc myprogram"

Which, BTW, is how Lazarus makes its calls; if it were not admitted it would be impossible to compile a Lazarus project.

FP (the text-mode IDE) had, IIRC, a problem with non-standard extensions in that it didn't highlight correctly the source  in the editor (it wasn't recognized as Pascal source). I don't remember ATM whether that was corrected, though.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018