freepascal

How to avoid violating the DRY principle when the boolean expression of a while loop is reassigned every loop pass?

喜欢而已 提交于 2019-12-12 03:49:34
问题 Both while MyFunction(1, 2, 3) > 0 do begin Temp := MyFunction(1, 2, 3); ShowMessage(IntToStr(Temp)); end; and Temp := MyFunction(1, 2, 3); while Temp > 0 do begin ShowMessage(IntToStr(Temp)); Temp := MyFunction(1, 2, 3); end; violate the DRY principle because there are two calls to MyFunction when only one is necessary. 回答1: Easy, function dotemp(a,b,c:integer;var value : integer):boolean; begin value:a*b+c; result:=value>0; end; begin while dotemp(a,b,c,temp) do begin Operateontemp(temp);

How can I increase the size of the console inside the code

橙三吉。 提交于 2019-12-12 01:25:34
问题 I'm doing some code in pascal using lazarus IDE v1.8.4, as the question says I need to be able to edit the console size in the code, I also preferably need to get the max possible console width they can have. If you do know how please also let me know the uses you.. used. Thanks! 回答1: Assuming you're targeting Windows: Use GetLargestConsoleWindowSize to retrieve the largest possible console size depending on the console font and display settings, Use SetConsoleScreenBufferSize to set the

Can a Windows GUI program written in Lazarus create a console and write to it at runtime?

こ雲淡風輕ζ 提交于 2019-12-11 08:29:08
问题 When writing a Lazarus program, you have the option of using $APPTYPE console or deselecting the Win32 GUI Application ( -WG option) in the Project Options . I noticed that without these options DebugLn and WriteLn raise exceptions. Is there a way to create a console even if the program is not compiled above mentioned options and output to it with DebugLn and WriteLn afterwards? 回答1: In windows it is a little more tricky compared to Delphi. In Delphi all you need to do is to call AllocConsole

Linking SDL_image errors

心不动则不痛 提交于 2019-12-11 07:09:49
问题 I am trying to install UltraStarDeluxe on a linux machine. The make uses compile scripts generated by fpc (Free Pascal) . On invoking make , the following is the error+warning message before ld exits: /usr/bin/ld: warning: ../game/link.res contains output sections; did you forget -T? /usr/bin/ld: cannot find -lSDL_image /home/sriram/ultraDX/ultrastardx-1.1-src/src/ultrastardx.dpr(344,1) Error: Error while linking /home/sriram/ultraDX/ultrastardx-1.1-src/src/ultrastardx.dpr(344,1) Fatal: There

Using event listeners in a non-gui environment (DLL) (Delphi)

梦想与她 提交于 2019-12-11 04:46:45
问题 I am attempting to convert a GUI application that I made in Delphi (actually, its Lazarus) to a library(DLL). In the GUI application I used a OnDataChange event listener, but I cannot seem to figure out how to do the same thing for the library. Here is what it looks like in the GUI App: procedure TForm1.Datasource2DataChange(Sender: TObject; Field: TField); begin ZMakeRankedTable.Close; GetNN; end; And in the unit's LFM file: object Datasource2: TDatasource DataSet = ZMakeRankedTable

How do you escape a reserved word in Free-Pascal?

心已入冬 提交于 2019-12-11 02:31:59
问题 Actually i'am working on translate some librarys to free-pascal. so the problem is which in delphi can use the ampersand (&) symbol to escape a reserved word, but in free-pascal does not work. the compiler complains with this message ForLibDx.pas(72,13) Fatal: illegal character "'&'" ($26) when include an ampersand symbol. actually i am using the {$MODE DELPHI} to compile my units under free-pascal FPC 2.2.4 Lazarus 0.9.28.2 thanks in advance. 回答1: From what I recollect, the FPC compiler does

Pascal passing a listview from mainform to a nonmodal form

♀尐吖头ヾ 提交于 2019-12-11 00:44:14
问题 I have a listview in my mainform that I want another nonmodal form to be able to add things to. How would I pass the listview to the nonmodal form? The form I want to be able to modify it is shown by the MainForm on a button click, just with Form.Show. I should also clarify that I want the form to not use the mainform to avoid circular reference. 回答1: The simplest and best way would be to add a method to the receiving form - that is, the form with the ListView on it -- that says

Using a indentifier or reserved word in a automation object under FPC

大兔子大兔子 提交于 2019-12-10 19:51:28
问题 Actually i am using OLE automation under Free Pascal , but some objects have properties which uses reserverd words as names, so i cannot compile the code. check this sample MyObj : OleVariant; begin MyObj := CrealeOleObject('AObject'); MyObj.Descriptor := Param1; MyObj.Type := Param2; //this line generates a error this is the error StdOleAux.pas(783,15) Fatal: Syntax error, "identifier" expected but "TYPE" found so the question is how i can access this properties in FPC when they have a name

Free Pascal/C++ project crashes in cout::sentry

你。 提交于 2019-12-10 18:51:16
问题 I have a mixed Free Pascal/C++ project. Debian 5.0 ("Lenny") on i386, FPC 2.4.4. When I run the program, it crashes on the first cout<< call. Funnily, it used to work for some time; some OS update probably broke it. Here's the issue isolated: p.pas: {$L c.o} program p; uses initc; procedure Hello; cdecl; external name 'Hello'; begin Hello; end. c.cpp: #include <iostream> //void * __dso_handle; //You might need to uncomment that extern "C" void Hello() { std::cout << "Hello world"; } Makefile:

Assembly calls to System unit functions on FreePascal x64

对着背影说爱祢 提交于 2019-12-10 15:40:01
问题 I have some Delphi/assembly code that compiles and works fine (XE2) for Win32, Win64, and OSX 32. However, since I need it to work on Linux, I have been looking at compiling FPC versions of it (so far, Win32/64, Linux32/64). By and large, it works well, but the one thing I have not been able to get to work are calls/jumps to Delphi System unit functions, like such: jmp System.@FillChar This appears to have the desired effect on FPC Win32/Linux32, but fails with an exception on FPC Win64