Lazarus problem after new Version lazarus / 21-General ---------------------------------------------------------------------- Moombas · 2021-01-27 09:52 Hi all, because of new PC-Installation i use now the actual Lazarus Version but get an error when trying to compile a project: fpg_oledragdrop.pas(113,23) Error: No matching implementation for interface method "SetData(const tagFORMATETC;var TagSTGMEDIUM;LongBool):LongInt; StdCall;" found I found a change here: https://github.com/graemeg/fpGUI/blob/cbe4f70f2 546252fbad0e6a380ce7b1f9e8439a3/src/corelib/gdi/fpg_oledragdrop.pas But if i apply it, i get different errors in same file: fpg_oledragdrop.pas(193,15) Error: Identifier not found "MIME_TEXT_PLAIN" fpg_oledragdrop.pas(199,15) Error: Identifier not found "MIME_TEXT_URI_LIST" fpg_oledragdrop.pas(201,15) Error: Identifier not found "MIME_TEXT_HTML" ... fpg_oledragdrop.pas(655,16) Warning: use of NEW or DISPOSE for untyped pointers is meaningless fpg_oledragdrop.pas(746,28) Error: Identifier not found "TfpgNativeWindow" I read something about that there changed something but how to fix this.  Even i don't use drag and drop, but i think it's a general one!? I really need help here, need to compile the program I mixed now both version up, hopefully it doesn't take side effects there... (not working parts of "new" version replaced with working parts of old version. But now i got a problem in my compiled program, that it's not finding files -.- Does anyone know why following is only creating the "root" folder but not copy any files/dirs anymore: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TTools.CopyDir(SourceDirectory: WideString; DestinationDirectory: WideString): boolean;var  SHFileOpStruct: TSHFileOpStructW;  SourceBuffer, DestinationBuffer: array[0..255] of char;  res: integer;begin  try    if not SysUtils.DirectoryExists(SourceDirectory) then    begin      Result := False;      exit;    end;    Fillchar(SHFileOpStruct, sizeof(SHFileOpStruct), 0);    FillChar(SourceBuffer, sizeof(SourceBuffer), 0);    FillChar(DestinationBuffer, sizeof(DestinationBuffer), 0);    StrPCopy(SourceBuffer, String(SourceDirectory));    StrPCopy(DestinationBuffer, String(DestinationDirectory));    with SHFileOpStruct do    begin      Wnd := 0;      wFunc := FO_COPY;      pFrom := @SourceBuffer;      pTo := @DestinationBuffer;      fFlags := FOF_ALLOWUNDO;      hNameMappings := nil;      lpszProgressTitle := nil;       fFlags := fFlags or FOF_NOCONFIRMATION;      fFlags := fFlags or FOF_SILENT;      fFlags := fFlags or FOF_SIMPLEPROGRESS;    fFlags := fFlags or FOF_NOCONFIRMMKDIR;    end;    res := SHFileOperationW(@SHFileOpStruct);    Result := (res = 0);     if not Result then    begin      ShowMessage(SysErrorMessage(GetLastError));    end;  except    Result := False;  end;end; ---------------------------------------------------------------------- ASerge · 2021-01-27 18:10 Quote from: Moombas on January 27, 2021, 10:52:51 amDoes anyone know why following is only creating the "root" folder but not copy any files/dirs anymore: First, Char in FPC is AnsiChar, but the structure assumes WideChar. Second, the pFrom and pTo parameters must end with a double zero, as stated in the documentation. Third, it is useless to call GetLastError, this is also mentioned in the documentation. Fourth, the "try except end" construction without error handling is a bad design. You may miss an important error. If you don't process something, leave it for the calling code. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ShellApi; function CopyDir(const SourceDirectory, DestinationDirectory: string): Boolean;var  SHFileOpStruct: TSHFileOpStructW;  SourceBuffer, DestinationBuffer: UnicodeString;begin  if not SysUtils.DirectoryExists(SourceDirectory) then    Exit(False);  FillChar(SHFileOpStruct, SizeOf(SHFileOpStruct), 0);  SourceBuffer := UTF8Decode(SourceDirectory) + #0#0; // or can be only have one #0, given a string implements   DestinationBuffer := UTF8Decode(DestinationDirectory) + #0#0;  with SHFileOpStruct do  begin    wFunc := FO_COPY;    pFrom := Pointer(SourceBuffer);    pTo := Pointer(DestinationBuffer);    fFlags := FOF_ALLOWUNDO;    fFlags := fFlags or FOF_NOCONFIRMATION;    fFlags := fFlags or FOF_SILENT;  fFlags := fFlags or FOF_SIMPLEPROGRESS;    fFlags := fFlags or FOF_NOCONFIRMMKDIR;  end;  Result := (SHFileOperationW(@SHFileOpStruct) = 0);end; ---------------------------------------------------------------------- wp · 2021-01-27 18:45 Quote from: Moombas on January 27, 2021, 10:52:51 amfpg_oledragdrop.pas(113,23) Error: No matching implementation for interface method "SetData(const tagFORMATETC;var TagSTGMEDIUM;LongBool):LongInt; StdCall;" found I met this in virtualTreeViews, too. This is how it is solved there: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // old declaration    function SetData(const FormatEtc: TFormatEtc; const Medium: TStgMedium; DoRelease: BOOL): HResult; virtual; stdcall; // new declaration    function SetData(const FormatEtc: TFormatEtc;      {$IF FPC_FullVersion >= 30200}var{$ELSE}const{$IFEND} Medium: TStgMedium;      DoRelease: BOOL): HResult; virtual; stdcall;  This means that you must replace the "const" before the TStgMedium parameter by "var" for FPC 3.2+ ---------------------------------------------------------------------- Moombas · 2021-01-28 07:08 Many thanks @ ASerge, i didn't wrote that part by myself but your "corrected" part is fine and works well. So many many thanks for that! @wp: Thanks for that too, i'll leave it now as it is but if there's coming something strange up, i'll keep this in mind. So, thanks for that too. ---------------------------------------------------------------------- Moombas · 2021-01-28 10:35 Now all works fine but when i shut down the programm or run the routine a secondtime i get an exception after i used a copy/execute job (see picture attached). The strange thing is, that during runtime, there's no error, only when quitting the program... i never had an issue like that, can someone help me how to debug this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TTools.KopierenClick(Sender: TObject);var  buttonSelected : Integer;  PfadA, PfadB   : WideString;  i              : Integer;begin  Fail.Clear;  Timer3.Interval  := strtoint(Delay.Text) * 1000;   if (Programs.itemindex >= 0) and     (Programs.Items[Programs.itemindex] <> '.') then  begin    if (Data.itemindex >= 0) and       (split(Data.items[Data.itemindex],'.',1) = 'exe') then    begin      if SysUtils.DirectoryExists(KopierenE.Text + Programs.items[Programs.itemindex]) then      begin        if DatenC.Checked then        begin          StartCopy();        end else if OriginalE.text <> InstallE.Text then        begin          buttonSelected := messagedlg('Das Programm existiert bereits im Installationsordner. Überschreiben?',mtCustom, [mbYes,mbCancel], 0);        if buttonSelected = mrYes then          begin            StartCopy();          end;        end else        begin          StartCopy();        end;      end else      begin        StartCopy();      end;      LastList.LoadFromFile(KopierenE.Text + Programs.items[Programs.itemindex] + '\test.txt');      Last.Enabled := True;    end else if HinweisC.Checked = False then    begin      showmessage('Es wurde keine Exe gewählt.');    end;     PfadA := PfadP + WideString(Programs.items[Programs.itemindex]) + WideString('\test.txt');    PfadB := WideString(InstallE.Text + Programs.items[Programs.itemindex] + '\test.txt');    copyfile(PWideChar(PfadA), PWideChar(PfadB), false);    BezirkS.Enabled    := False;    FilialeC.Enabled   := False;    FilialenPS.Enabled := False;    Manuell.Enabled    := False;    Last.Enabled       := False;    DatenC.Enabled     := False;    FertigC.Enabled    := False;    LogC.Enabled       := False;    StartP.Enabled     := False;    Escape.Enabled     := True;   end else if HinweisC.Checked = False then  begin    showmessage('Es wurde kein Programm gewählt.');  end;end; //Kopieren startenprocedure TTools.StartCopy();var  Status : Bool;begin  delete(Widestring(KopierenE.Text + Programs.items[Programs.itemindex]));  Status := copydir(PfadP + WideString(Programs.items[Programs.itemindex]), WideString(KopierenE.Text));  if Status then  begin    sFileAction    := 'Create';    Kopieren.Enabled := False;    NewLog(Widestring(KopierenE.Text + Programs.items[Programs.itemindex]));    Progress.Visible := True;    Progress.Position:= 0;    ProgressTimer.Enabled := True;    if StartP.checked then    begin      startasUser(WideString(KopierenE.Text + Programs.items[Programs.itemindex] + '\' + Data.items[Data.itemindex]), KopierenE.Text + Programs.items[Programs.itemindex] + '\');    end else    begin      Run.Enabled := True;    end;  end;end;      //Prozess als bestimmten Benutzer starten (Hilfsaufruf)procedure TTools.startasUser(exe: Widestring; param: string);var  User              : WideString;  PW              : WideString;  err               : DWORD;begin  User := 'Test';  PW   := 'PW';  err  := CreateProcessAsLogon(User, PW, exe, WideString(param), '');  if err <> 0 then  begin    ShowMessage(SysErrorMessage(err));  end;end;   function TTools.CreateProcessAsLogon(const User, PW, Application, param, CmdLine: WideString): DWORD;var  ws  : WideString;  si  : TStartupInfoW;  pif : TProcessInformation;begin  ZeroMemory(@si, sizeof(si));  si.cb := sizeof(si);  si.dwFlags := STARTF_USESHOWWINDOW;  si.wShowWindow := 1;   if CmdLine = '' then  begin    ws := Application;  end else  begin    ws := Application + ' "' + CmdLine + '"';  end;   SetLastError(0);  SI.cb  := SizeOf(TStartupInfo);  if CreateProcessWithLogonW(PWideChar(User), nil, PWideChar(PW), 0, nil, PWideChar(ws), CREATE_DEFAULT_ERROR_MODE, nil, PWideChar(param), @si, @pif) then  begin    sleep(500);    if PIf.dwProcessId > 0 then    begin      AppPID := PIf.dwProcessId;    CloseHandle(PIf.hProcess);      CloseHandle(PIf.hThread);    end;  end;  Result := GetLastError;end;  function CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword: LPWSTR; dwLogonFlags: dword; lpApplicationName,  lpCommandLine: LPWSTR; dwCreationFlags: dword; lpEnvironment: pointer; lpCurrentDirectory: LPWSTR; lpStartupInfo:  PStartUpInfoW; lpProcessInfo: PProcessInformation): boolean; stdcall; external 'advapi32.dll';  procedure TTools.OnNotifySynchronized();begin  Timer3.Enabled := true;end;        procedure TTools.OnNotify(const FilePath: WideString; const Action: TDirectoryEventType);var  start, i : integer;  FileName : WideString;begin  FileName := '';  start := 1;  for i := length(FilePath) downto 1 do  begin    if FilePath[i] = '\' then    begin      start := i + 1;      break;    end;  end;   for i := start to length(FilePath) do  begin    FileName := FileName + FilePath[i];  end;   if (Split(String(FileName), '2', 0) = 'Log') or     (Split(String(FileName), '2', 0) = 'log') then  begin    case Action of      detAdded: begin                  Instant.Enabled := True;                Run.Enabled     := False;                  LogL.Caption    := String(Filename + ' gefunden.');                  LogL.Left       := 72;                  LogA.Caption    := 'Logdatei prüfen...';                LogA.Show;                  sFileAction     := 'Edited';                //Watch.Stop;                  //Watch.Destroy                LogDatei        := Filename;                  LogName         := FilePath;                  LogA.Caption    := DateTimeToStr(ReportFileTimes(LogName));                  LogA.Left     := 72;                  FileChange      := ReportFileTimes(LogName);                  olddate         := FileChange;                  TThread.Synchronize(nil, OnNotifySynchronized);                end;      detRemoved: ;      detModified: ;    end;  end;end; procedure TTools.NewLog(Path : WideString);begin  if sFileAction = 'Create' then  begin    if SysUtils.ForceDirectories(Path) then    begin      LogL.Caption       := 'Auf Log Datei warten...';      LogL.Show;      Programs.Enabled   := False;      Data.Enabled       := False;      TxTLogs.Enabled    := False;      Watch              := TDirectoryWatcherBuilder.New                                                  .WatchDirectory(Path)                                                  .Recursively(False)                                                  .OnChangeTrigger(OnNotify)                                                  .Build;      Watch.Start;    end else    begin      MessageDlg('Verzeichnis konnte nicht erstellt werden', TMsgDlgType.mtError, [mbOK], 0);    end;  end;end;    procedure TTools.Timer3Timer(Sender: TObject);  function GetProcessHandleFromID(ID: DWORD): THandle;  begin    result := OpenProcess(SYNCHRONIZE, False, ID);    CloseHandle(result);  end;begin  if fileexists(String(LogName)) then  begin    newdate := ReportFileTimes(WideString(LogName));    if newdate <> olddate then  begin      olddate := newdate;      Timer3.Enabled := True;    end else if AppPID <> 0 then    begin      if GetProcessHandleFromID(AppPID) = 0 then      begin        Timer3.Enabled   := False;        Progress.Visible := False;        ProgressTimer.Enabled := False;        if FertigC.Checked then        begin          FertigClick(Sender);        end else        begin        Fertig.Enabled := True;        end;        Run.Enabled      := False;        Programs.Enabled := True;        Data.Enabled     := True;        TxTLogs.Enabled  := True;        Escape.Enabled   := False;        LogA.Caption     := 'Programm fertig.';        Timer3.Enabled   := False;        AppPID           := 0;      end;    end else    begin      showmessage('Es wurde kein Programm gefunden!');      Timer3.Enabled   := False;      Progress.Visible := False;      ProgressTimer.Enabled := False;      if FertigC.Checked then      begin        FertigClick(Sender);      end else      begin      Fertig.Enabled := True;      end;      Run.Enabled      := False;      Programs.Enabled := True;      Data.Enabled     := True;    TxTLogs.Enabled  := True;      Escape.Enabled   := False;      LogA.Caption     := 'Programm nicht gefunden!';      Timer3.Enabled   := False;    end;  end;end; ---------------------------------------------------------------------- Moombas · 2021-01-28 11:03 After some Debugger settings i found, the error here: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i destructor TDirectoryWatcherThreadWindows.Destroy;begin  try      if FhFile <> INVALID_HANDLE_VALUE then    begin      CloseHandle(FhFile);    end;     CloseHandle(FileEvent); // Error is here    TermEvent.Free;    SuspEvent.Free;  except  end;    FEventTriggerThread.FreeOnTerminate := True;  FEventTriggerThread.Terminate;  inherited;end; But this is in DirectoryWatcherThreadWindows.windows which is a lazarus unit, so whats going wrong here? Did i forgot to close/free this anywhere? ---------------------------------------------------------------------- Fred vS · 2021-01-28 12:21 Hello. Are you using fpGUI via LCL (Lazarus widget) ? If so it is possible that there are problems. LCL-fpGUI is work-in-progress state, you should use "Pure fpGUI" instead. https://github.com/graemeg/fpGUI/tree/maint Fre;D ---------------------------------------------------------------------- Moombas · 2021-01-28 13:08 @Fred vS: How to check that? This "project" is quite old and long untouched, so sorry for the stupid question. But does it really take effect on directorywatcher? ---------------------------------------------------------------------- Fred vS · 2021-01-28 15:38 Quote from: Moombas on January 28, 2021, 02:08:55 pm@Fred vS: How to check that? This "project" is quite old and long untouched, so sorry for the stupid question. But does it really take effect on directorywatcher? If your project was created via Lazarus and you did choose in project option: LCLWidgetType:=fpgui then for sure it is the LCL-fpGUI widget that is used. You may check this in your code of unit "program". If there is in uses section: interfaces then LCL widgetset is used, otherwise it is a "Pure fpGUI" widget used. Anyway, if you a had success with WidgetType:=fpgui with older version of Lazarus and now problems appear, please create a issue here: https://github.com/graemeg/fpGUI/issues Fre;D ---------------------------------------------------------------------- Moombas · 2021-01-29 06:43 Ok, so i seem to use the working version, because "interfaces" are not in uses. But i still have the directorywatcher problem ---------------------------------------------------------------------- Moombas · 2021-01-29 11:07 I read in a different Thread that SIGSEGV (there) could be because of a dll call, which happens here too. Can someone help me here? I'm really helpless at the moment.