* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
Beginners / Re: Error: Identifier not found "try"
« Last post by molly on Today at 05:28:39 am »
Place {$MODE OBJFPC} or {$MODE DELPHI} beneath your program declaration.

The reason is that by default the compiler will compile in MODE FPC, which does not support exceptions.

More on the subject can be read here in the user's guide.

Edit: Or perhaps even better explained, here in the programmers guide.
2
Beginners / Error: Identifier not found "try"
« Last post by beampower on Today at 05:07:29 am »
I'm using Free Pascal IDE for Win32 for i386.
I'm trying manage some error handling using Try ... Except in Pascal.
An example of code is listed below.
It doesn't even get past the compile step.
I get Error: Identifier not found "try".
What's up?

Code: Pascal  [Select]
  1. program exception1;
  2.     var
  3.         num1, num2, num3 : Integer;
  4.     begin
  5.         try
  6.             num1 := 0;
  7.             num2 := 1;
  8.             num3 := num2 div num1;
  9.             ShowMessage('1 / 0 = '+IntToStr(num3));
  10.         except
  11.             on E : Exception do
  12.             begin
  13.                 ShowMessage('Exception class name = '+E.ClassName);
  14.                 ShowMessage('Exception message = '+E.Message);
  15.             end;
  16.         end;
  17.     end;



4
Beginners / Re: Overwrite curent line
« Last post by samoraj on Today at 04:02:45 am »
I cheching configuration on laptops and everyone laptop saving his configuration on one file in network (buffer directory 'C:\Users\Public\print\check') with name matherboard name. My program geting this file and saving in another file 'C:\Users\Public\print\checkall\all.csv' . If buffer file name exist in 'C:\Users\Public\print\checkall\all.csv' like text, i want to replace information in curent line on 'C:\Users\Public\print\checkall\all.csv' with a new information from (buffer directory 'C:\Users\Public\print\check') , because the laptop configuration may be a diferent (ram, hdd, odd).
5
Graphics / Re: Graphics Contest 2017
« Last post by User137 on Today at 03:58:07 am »
@Marco
I suspect you mean this?
http://forum.lazarus.freepascal.org/index.php?action=dlattach;topic=35313.0;attach=19516;image

Great game!! Sometimes I win!  8)
I did mention i only made it work in Win10. I don't have a Linux, and it's never been kind to me when trying to run Linux on virtual machine with hardware accelerated graphics. It said it compiled too, so i don't have any possible suggestions to give. If anyone can tell what goes wrong it would be appreciated. Either it's a threading problem with sudoku algorithm or something might be going wrong with dglOpenGL on Linux. Only you guys can tell how to fix it, private message or anything.
6
Beginners / Re: Overwrite curent line
« Last post by samoraj on Today at 03:48:32 am »
Because filename1 and first line in filename1 its Identical . If my file name is test.txt , my first line in file test.txt is 'test' and i want to checking if file name exist in
'C:\Users\Public\print\checkall\all.csv' then to replace a old lines with begin line file name with text information on filename.
7
Networking and Web Programming / Re: VTX Client/Server
« Last post by codewar65 on Today at 03:25:35 am »
But now if the client drops connection, the server blows up. And I am unable to find out where the segfault is happening in the debugger. I will have to pull this apart and put it back together piece by piece. I'm sure it's just a rookie mistake, but you can't make an omelette without breaking a few eggs.  %)
8
Beginners / Re: Overwrite curent line
« Last post by taazz on Today at 03:09:56 am »
you already have the first file in memory.
Code: Pascal  [Select]
  1. procedure TPrint.Timer1Timer(Sender: TObject);
  2.  
  3.     var
  4.     searchResult : TSearchRec;
  5.     myfile, myfile1: text;
  6.     found : boolean;
  7.     sl : TStringList;
  8.     s: string;
  9.     i:integer;
  10.     count:integer;
  11.     File1, File2: TextFile;
  12.     vCntr : integer;//nothing new just a counter.
  13.   begin
  14.     SetCurrentDir('C:\Users\Public\print\check');
  15.     if findfirst('*', faAnyFile, searchResult) = 0 then
  16.     begin
  17.       repeat
  18.         statictext4.Caption:=searchResult.Name;
  19.       until FindNext(searchResult) <> 0;
  20.     end;
  21.     if (searchResult.Name<> '.') and (searchResult.Name<> '..') then
  22.     begin
  23.        if  FileExists('C:\Users\Public\print\checkall\all.csv') then
  24.           begin
  25.            count := 0;
  26.            found := false;
  27.            sl := TStringList.Create;
  28.            filename1 := StaticText4.Caption;
  29.            filename2 := copy(filename1,0,(length(filename1)-4));
  30.           try
  31.              sl.LoadFromFile('C:\Users\Public\print\checkall\all.csv');
  32.                for vCntr := 0 to sl.count -1 do begin //use a for loop instead.
  33.                  if Pos(filename2, sl[Vcntr])<>0 then begin
  34.                    //read the first line from the other file in the line variable
  35.                    sl[Vcntr] := line; //replace the existing line with the new
  36.                    //read the second line from the other file in the line variable
  37.                    sl[vCntr+1] := line; //replace the second line with the new
  38.                    //read the third line from the other file in the line variable
  39.                    sl[vCntr+2] := line; //replace the third line with the new
  40.                    //read the fourth line from the other file in the line variable
  41.                    sl[vCntr+3] := line; //replace the fourth line with the new
  42.                    //read the fifthline from the other file in the line variable
  43.                    sl[vCntr+4] := line; //replace the fifth line with the new
  44.                    break; //exit the for loop;
  45.                  end;
  46.                end;
  47.                  sl.savetofile('C:\Users\Public\print\checkall\all.csv');//replace the file data with the new data.
  48.                    finally
  49.                      sl.Free;
  50.               end;
  51.            end;
  52.           end;
  53.     begin
  54.     SetCurrentDir('C:\Users\Public\print\check');
  55.     if findfirst('*', faAnyFile, searchResult) = 0 then
  56.     begin
  57.       repeat
  58.         statictext4.Caption:=searchResult.Name;
  59.       until FindNext(searchResult) <> 0;
  60.     end;
  61.     if (searchResult.Name<> '.') and (searchResult.Name<> '..') then begin
  62.  
  63.       //SERIAL MATHERBOARD
  64.      filename := StaticText4.Caption;
  65.      StaticText5.Caption:=filename;
  66.      if  FileExists(statictext4.Caption) then
  67.          begin
  68.  
  69.   assignfile(File1,'C:\Users\Public\print\check\'+statictext4.Caption);
  70.   assignfile(File2,'C:\Users\Public\print\checkall\all.csv');
  71.   reset(File1); //open for read;
  72.   append(File2); //asumes File2 can be written to, puts filepointer at end of the file
  73.   while not Eof(File1) do
  74.   begin
  75.     readln(File1,S); //read a line frome file1
  76.     writeln(File2,S); //write the line to file2
  77.   end;
  78.   CloseFile(File1);
  79.   CloseFile(File2);
  80.      Erase (File1); //  delete file
  81.       AssignFile(F, 'C:\Users\Public\print\checkall\all.csv');
  82.        Append(f);
  83.     CloseFile(F);
  84.      end;
  85.      end;
  86.  end;
  87. end;
  88.  
I cange line 47. with sl.savetofile('C:\Users\Public\print\checkall\all.csv');
When i create file filename2 second time the program not replace lines, delete old lines and in new lines recording. How i fix this ?
http://alfa.kachi-snimka.info/images-2013/opt1500684110g.jpg
http://alfa.kachi-snimka.info/images-2013/arx1500684157i.jpg
i want to replace existing lines.
Code: Pascal  [Select]
  1.   begin
  2.     SetCurrentDir('C:\Users\Public\print\check');
  3.     if findfirst('*', faAnyFile, searchResult) = 0 then begin
  4.       repeat
  5.         statictext4.Caption:=searchResult.Name;
  6.       until FindNext(searchResult) <> 0;
  7.     end;
  8.  
  9.     if (searchResult.Name<> '.') and (searchResult.Name<> '..') then begin
  10.       //SERIAL MATHERBOARD
  11.       filename := StaticText4.Caption;
  12.       StaticText5.Caption:=filename;
  13.       if  FileExists(statictext4.Caption) then begin
  14.         assignfile(File1,'C:\Users\Public\print\check\'+statictext4.Caption);
  15.         assignfile(File2,'C:\Users\Public\print\checkall\all.csv');
  16.         reset(File1); //open for read;
  17.         append(File2); //asumes File2 can be written to, puts filepointer at end of the file
  18.         while not Eof(File1) do begin
  19.           readln(File1,S); //read a line frome file1
  20.           writeln(File2,S); //write the line to file2
  21.         end;
  22.         CloseFile(File1);
  23.         CloseFile(File2);
  24.         Erase (File1); //  delete file
  25.         AssignFile(F, 'C:\Users\Public\print\checkall\all.csv');
  26.         Append(f);
  27.         CloseFile(F);
  28.       end;
  29.     end;
  30.   end;
  31.  
why are you keep on processing the same files below? try deleting the above code.
9
Beginners / Re: LoadLibrary + Threads = Crash?
« Last post by Phil on Today at 03:00:46 am »
Here is a updated version for all, that includes buffer + length and that will work with all platforms:

You're assuming PChar points to single-byte chars? Not the case with Delphi. Better use PAnsiChar.

See the ndfd.pas library and ndfd_types.pas files in Parts 2 and 3 here for more ideas. It's generally a good idea to fully define your types. See FPC ctypes.pp unit also.

https://macpgmr.github.io/MacXPlatform/PascalDynLibs.html


10
Beginners / Re: LoadLibrary + Threads = Crash?
« Last post by Benjiro on Today at 02:53:31 am »
Note that COM is a Windows-only technology.

Here is a updated version for all, that includes buffer + length and that will work with all platforms:

Code: Pascal  [Select]
  1. library dll_hello;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses SysUtils;
  6.  
  7. function Process(const Buffer: PChar; const Len: Integer; Num1: Integer): Boolean; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
  8. begin
  9.     StrLCopy(Buffer, 'Hello World', Len);
  10.     Result := True;    
  11. end;
  12.  
  13. exports
  14.   Process;
  15.  
  16. begin
  17. end.

Code: Pascal  [Select]
  1. unit xLoader;
  2. {$mode objfpc}{$H+}
  3.  
  4. interface
  5.  
  6. function CallDll (LibraryName : String) : String;
  7.  
  8. type
  9.     TMyFunc = function (const Buffer: PChar; const Len: Integer; Num1: Integer): Boolean; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF}; // The called function parameters ...  cdecl; for linux??
  10.  
  11. implementation
  12.  
  13. uses DynLibs, sysutils;
  14.  
  15. //////////////////////////////////////////////////
  16. // CallDll Function
  17. //////////////////////////////////////////////////
  18.  
  19. function CallDll (LibraryName : String) : String;
  20. var
  21.     MyFunc: TMyFunc;
  22.  
  23.     LibHandle: TLibHandle = dynlibs.NilHandle;
  24.     FuncBuffer: String;
  25.     BuffLen: Integer;  
  26. begin
  27.     LibHandle := LoadLibrary(LibraryName + '.dll');// + SharedSuffix);
  28.  
  29.     if LibHandle = dynlibs.NilHandle then
  30.     begin
  31.         Writeln('DLL was not loaded successfully');
  32.         Exit;
  33.     end;
  34.  
  35.     Pointer(MyFunc) := TMyFunc(GetProcedureAddress(LibHandle, 'Process')); // Call the function "Process"
  36.     if @MyFunc = nil then
  37.       Writeln('GetProcedureAddress called and failed');
  38.  
  39.     FuncBuffer := '';
  40.     BuffLen := 55;
  41.  
  42.     SetLength(FuncBuffer, BuffLen);     // Allocate space for return value
  43.  
  44.     MyFunc ( PChar(FuncBuffer), BuffLen, 1);  //Executes the function
  45.  
  46.     MyFunc := nil;
  47.     if LibHandle <> DynLibs.NilHandle then
  48.         if FreeLibrary(LibHandle) then LibHandle:= DynLibs.NilHandle;  //Unload the lib, if already loaded
  49.      
  50.     Result := FuncBuffer;
  51. end;
  52.  
  53. end.

I hope this is off use for people in the future.
Pages: [1] 2 3 ... 10

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus