Recent

Author Topic: New user - help with error  (Read 789 times)

chuckles1066

  • New Member
  • *
  • Posts: 20
New user - help with error
« on: July 04, 2020, 10:40:35 am »
I'm hoping that someone can see my problem, it's baffling me (but I am a newbie to this so apologies).

My code falls over right at the end:
Code: [Select]
library TomGenuineWithForm;
{$mode objfpc}{$H+}
uses
  SysUtils,
  windows,
  forms,
  math,
  diceDlg in 'diceDlg.pas' {PickDiceDlg};

{$R *.res}
var
  RandomizeAlreadyCalled: Boolean = False;


//make sure the call is stdcall;
function Dice: Integer; {$ifdef windows}stdcall{$else}cdecl{$endif};
//function Dice: Integer; stdcall;
var
  D1, D2: Integer;
  T : Dword;
begin
  // call randomize once and never again.
  if not RandomizeAlreadyCalled then begin
    Randomize;
    RandomizeAlreadyCalled := True;
  end;

  D1 := Random(6) + 1;
  D2 := Random(6) + 1;

  Result := D1 * 8 + D2;

  //If form do not exists create it
  if PickDiceDlg=nil then
    application.CreateForm(TPickDiceDlg,PickDiceDlg);
  With PickDiceDlg do
  Begin
    //Show the form
    if not Visible then
      Show;

    //If delay
    if cbWait.checked then
    Begin
      //Display the next dice to come
      lNextdice.caption  := Inttostr(MaxIntValue([D1,D2]))+ Inttostr(MinIntValue([D1,D2]));
      lNextdice2.visible := true;
      lNextdice.visible  := true;
      //Because there is no mesage loop, force the refresh of the form
      Repaint;
      T := GetTickcount;
      //Make a loop that create the delay
      //DO NOT use a application.processMessages or equivalent or it will not work
      while GetTickcount-T<dword(spDelay.value*1000) do
      Begin
      end;
      //Hide the next dice upon release
      lNextdice2.visible := false;
      lNextdice.visible  := false;
    end;
    // Add the dice to the top of the list
    lbDiceList.items.insert( 0, Inttostr(D1)+Inttostr(D2) );
  end;
end;

//Export the dice function by name
exports Dice;

procedure LibraryProc(Reason: Integer);
Begin
  //upon exit destroy the form
  Case reason of
    DLL_PROCESS_DETACH:
      if PickDiceDlg<>nil then
        PickDiceDlg.free;
  end;
end;

begin
  //Reinit the Random Number generator
  //randomize;
  //set the DLl procedure to handle the DLL_PROCESS_DETACH.
dllProc := @LibraryProc;
end.

First error message is "TomGenuineWithForm.pas(83,1) Error: Identifier not found "dllProc""

If I comment out the dllProc := @LibraryProc; line the error message is "TomGenuineWithForm.pas(84,1) Error: Can't open resource file "E:\Office\Lazarus\lcl\TomGenuineWithForm.res".

So frustrating because I've successfully worked my way through dozens of error messages (usually couldn't find file, my bad with path settings) but this one has me stumped......is there supposed to be a TomGenuineWithForm.res file somewhere?  I've searched my entire pc in case it had been dropped somewhere obscure but no joy.

I'm so close to getting this over the line, much appreciated if anyone could help.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: New user - help with error
« Reply #1 on: July 04, 2020, 11:47:26 am »
First error message is "TomGenuineWithForm.pas(83,1) Error: Identifier not found "dllProc""

There is no general DllProc. Instead there is a procedure variable for each of the three reasons:

Code: Pascal  [Select][+][-]
  1. type
  2.   TDLL_Entry_Hook = procedure (dllparam : PtrInt);
  3.  
  4. const
  5.   Dll_Process_Detach_Hook : TDLL_Entry_Hook = nil;
  6.   Dll_Thread_Attach_Hook : TDLL_Entry_Hook = nil;
  7.   Dll_Thread_Detach_Hook : TDLL_Entry_Hook = nil;
  8.  

So for your case you need to assign a suitable function to Dll_Process_Detach_Hook.

If I comment out the dllProc := @LibraryProc; line the error message is "TomGenuineWithForm.pas(84,1) Error: Can't open resource file "E:\Office\Lazarus\lcl\TomGenuineWithForm.res".

Normally the Lazarus IDE should generate a suitable res file for you. You could try to play around in Project Options -> Project Options -> Application or -> Ressources. Otherwise you can comment the {$ *.res} line as well for now.

chuckles1066

  • New Member
  • *
  • Posts: 20
Re: New user - help with error
« Reply #2 on: July 04, 2020, 11:57:16 am »
Thank you for your quick response, much appreciated, I'll see what I can do.

 

TinyPortal © 2005-2018