Einzelnen Beitrag anzeigen

Ginko

Registriert seit: 30. Aug 2008
208 Beiträge
 
FreePascal / Lazarus
 
#1

Text von Res (Resource Datei) in Lazarus-Projekt laden, Filestream leer [gelöst]

  Alt 24. Apr 2013, 11:02
Hallo, diese Anleitung http://wiki.freepascal.org/Lazarus_Resources habe ich benutzt und eine RES-Datei für Lazarus zu erstellen. Hat auch geklappt und die RES-Datei ist genau so groß wie der ursprüngliche Text der ausgangsdatei.
Allerdings ist der Filestream immer leer wenn ich ihn eingelesen habe. (Wenn ich direkt mit dem Debugger reingehe meine ich, klar ist das er bei finally ja wieder freigeben wird.)
Es kommt kein Compilerfehler.


Hier der Code:

Delphi-Quellcode:
program project1;

{$mode objfpc}{$H+}


uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, Unit1
  { you can add units after this },
  Classes, SysUtils, FileUtil, Controls, Graphics, Dialogs, StdCtrls,
  Windows;

//{$R *.res}
{$R xId.res}

var
  S: TResourceStream;
  F: TFileStream;
    StrList:TStringList;
begin
  // create a resource stream which points to our resource
  S := TResourceStream.Create(HInstance, 'XID', RT_RCDATA);
  // Please be aware of writing an apostrophes in resource type - source will not be axtracted!!!
  try
    // create a file mydata.dat in the application directory
    F := TFileStream.Create(ExtractFilePath(ParamStr(0)) + 'xId.txt', fmCreate);
        StrList := TStringList.Create;
    try
      F.CopyFrom(S, S.Size); // copy data from the resource stream to file stream
      StrList.LoadFromStream(F);
    finally
      F.Free; // destroy the file stream
      StrList.Free;
    end;
  finally
    S.Free; // destroy the resource stream
  end;

  RequireDerivedFormResource := True;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Geändert von Ginko (24. Apr 2013 um 13:15 Uhr)
  Mit Zitat antworten Zitat