本文介绍了如何正确声明StreamLn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译我的程序,但是我收到这个错误:

 未声明的标识符'StreamLn'
我甚至尝试下载PSock.dcu并将其放入库中,但它没有编译,它看起来像它的紧凑型delphi 5,

  unit ResourceInfo; 

接口

使用
类,SysUtils,Windows;

type
TResourceInfo = class;

TDfmMode =(dfmData,dfmResource,dfmASCII,dfmBinary);

TDfm = class
private
FOwner:TResourceInfo;
FName:string;
FData:TStream;

程序SetName(const Value:string);
procedure SetOwner(const Value:TResourceInfo);

public
构造函数Create(AOwner:TResourceInfo);
析构函数覆盖

函数SaveToFile(FileName:TFileName; Mode:TDfmMode):Boolean;

属性数据:TStream读取FData;
属性名称:字符串读取FName写SetName;
属性所有者:TResourceInfo读取FOwner写入FOwner;
结束{TDfm}

TResourceInfo = class(TComponent)
private
FActive:Boolean;
FDfms:TList;
FExeFileName:TFileName;
FModule:THandle;
FOnActivate:TNotifyEvent;
FOnDeactivate:TNotifyEvent;

过程SetExeFileName(const值:TFileName);
procedure SetActive(const Value:Boolean);
函数GetDfms(Index:Cardinal):TDfm;
函数GetDfmCount:Cardinal;

protected
程序清除;

public
构造函数Create(AOwner:TComponent);覆盖
析构函数覆盖

function AddDfm(const Name:string; AData:TMemoryStream):Integer;
procedure DeleteDfm(const Name:string);
属性DfmCount:Cardinal读取GetDfmCount;
属性Dfms [索引:Cardinal]:TDfm读取GetDfms;
程序EnumDfmNames;
属性模块:THandle读取FModule;

已发布
属性Active:Boolean读取FActive写入SetActive;
属性ExeFileName:TFileName读取FExeFileName写入SetExeFileName;

属性OnActivate:TNotifyEvent read FOnActivate write FOnActivate;
属性OnDeactivate:TNotifyEvent read FOnDeactivate write FOnDeactivate;
结束{TResourceInfo}

程序注册;

实现

使用
Winsock;

resourcestring
rsErrorLoadingExeFile ='错误加载文件%s,它可能不是可执行模块';

程序注册;
begin
RegisterComponents('+ HCU',[TResourceInfo]);
结束{注册}

{TResourceInfo}

函数TResourceInfo.AddDfm(const Name:string; AData:TMemoryStream):Integer;
var
FDfm:TDfm;
begin
FDfm:= TDfm.Create(Self);
FDfm.Name:= Name;
FDfm.Data.Size:= AData.Size;
FDfm.Data.Seek(0,0);
AData.Seek(0,0);
FDfm.Data.CopyFrom(AData,AData.Size);
结果:= FDfms.Add(FDfm);
结束{TResourceInfo.AddDfm}

构造函数TResourceInfo.Create(AOwner:TComponent);
开始
继承;

FActive:= False;
FDfms:= TList.Create;
FModule:= 0;
结束{TResourceInfo.Create}

析构函数TResourceInfo.Destroy;
开始
清除;
FDfms.Free;

继承;
结束{TResourceInfo.Destroy}

函数CB_EnumDfmNameProc(hModule:THandle; lpszType,lpszName:PChar; lParam:Integer):Boolean;标准
var
ms:TMemoryStream;
rs:TResourceStream;
缓冲区:字节数组;
begin
with TResourceInfo(lParam)do
begin
rs:= TResourceStream.Create(TResourceInfo(lParam).Module,lpszname,lpszType);
try
ms:= TMemoryStream.Create;
try
try
SetLength(Buffer,4);
rs.Read(Buffer [0],SizeOf(Buffer));
如果string(Buffer)='TPF0'然后
begin
rs.Seek(0,0);
ObjectBinaryToText(rs,ms);
ms.Seek(0,0);
AddDfm(StrPas(lpszName),ms);
结束

加注;
结束
finally
ms.Free;
结束
finally
rs.free;
结束
结束

结果:= True;
结束{CB_EnumDfmNameProc}

procedure TResourceInfo.EnumDfmNames;
begin
如果FModule> 0然后
EnumResourceNames(FModule,RT_RCDATA,@CB_EnumDfmNameProc,Integer(Self));
结束{TResourceInfo.EnumDfmNames}

procedure TResourceInfo.DeleteDfm(const Name:string);
var
i:红衣主教;
begin
如果FDfms.Count> 0 then
for i:= Pred(FDfms.Count)downto 0 do
if UpperCase(TDfm(FDfms [i])。Name)= UpperCase(Name)then
begin
FDfms.Delete(i);
休息;
结束
结束{TResourceInfo.DeleteDfm}

procedure TResourceInfo.SetActive(const Value:Boolean);
begin
如果FActive<>价值然后
开始
如果值然后
开始
如果FModule> 0然后
FreeLibrary(FModule);

(* LOAD_LIBRARY_AS_DATAFILE
如果给出此值,该函数将文件简单映射到
地址空间中,相对于执行或准备执行
在映射文件中的代码该函数加载模块就像是一个数据文件
您可以使用函数返回的模块句柄与这个操作的Win32
函数在资源上使用此标志,当您要在
订单中加载DLL以从其中提取消息或资源时,并且无意执行
其代码。如果未给出此值,则函数映射该文件以可执行模块的正常方式放入地址
空格中。在这方面
函数的行为与LoadLibrary的行为相同*)

FModule:= LoadLibraryEx( PChar(FExeFileName),0,LOAD_LIBRARY_AS_DATAFILE);
如果没有(FModule> = 32)然后
raise Exception.CreateFmt(rsErrorLoadingExeFile,[FExeFileName]);
如果分配(FOnActivate)然后
FOnActivate(Self);
end
else
begin
清除;
如果FModule> 0然后
开始
FreeLibrary(FModule);
FModule:= 0;
结束
如果分配(FOnDeactivate)然后
FOnDeactivate(Self);
结束
FActive:= Value;
结束
结束{TResourceInfo.SetActive}

procedure TResourceInfo.SetExeFileName(const Value:TFileName);
begin
如果FExeFileName<>值然后
FExeFileName:= Value;
结束{TResourceInfo.SetExeFileName}

函数TResourceInfo.GetDfms(Index:Cardinal):TDfm;
begin
结果:= TDfm(FDfms [Index]);
结束{TResourceInfo.GetDfms}

函数TResourceInfo.GetDfmCount:Cardinal;
begin
结果:= FDfms.Count;
结束{TResourceInfo.GetDfmCount}

procedure TResourceInfo.Clear;
begin
如果FDfms.Count> 0然后
,而FDfms.Count> 0 do
FDfms.Delete(0);
结束{TResourceInfo.Clear}

{TDfm}

构造函数TDfm.Create(AOwner:TResourceInfo);
开始
继承创建;

FData:= TMemoryStream.Create;
FName:='';
SetOwner(AOwner);
结束{TDfm.Create}

析构函数TDfm.Destroy;
begin
FData.Free;
继承;
结束{TDfm.Destroy}


函数TDfm.SaveToFile(FileName:TFileName; Mode:TDfmMode):Boolean;

函数EndOfStream(Stream:TStream):Boolean;
开始
与Stream do
结果:= Position = Size;
结束{EndOfStream}

var
fs:TFileStream;
ms:TMemoryStream
s:string;
i,j:Byte;
begin
fs:= TFileStream.Create(FileName,fmCreate或fmShareExclusive);
try
FData.Seek(0,0);

案例模式
dfmASCII:
begin
ms:= TMemoryStream.Create;
try
s:= FName +'RCDATA'+#13#10 +'{';
StreamLN(fs,s);

ObjectTextToBinary(FData,ms);
ms.Seek(0,0);

而不是EndOfStream(ms)do
begin
s:='''';

为i:= 0至15 do
begin
如果ms.Read(j,SizeOf(j))= 0,则
Break;
s = = Concat(s,Format('%2.2x',[j]));
if(i = 15)或EndOfStream(ms)then
s:= Concat(s,''')
else
s:= Concat(s,'');
结束

如果EndOfStream(ms)然后
s:= Concat(s,#13#10 +'}');
StreamLN(fs,s);
结束

finally
ms.Free;
结束
结束

dfmBinary:
ObjectTextToBinary(FData,fs);
结束

finally
fs.Free;
结束
结束{TDfm.SaveToFile}

procedure TDfm.SetName(const Value:string);
begin
如果FName<>值然后
FName:= Value;
结束{TDfm.SetName}

procedure TDfm.SetOwner(const Value:TResourceInfo);
begin
FOwner:= Value;
结束{TDfm.SetOwner}

end。

如何成功申报?

解决方案

对我来说,WinSock单元没有一个 StreamLn 函数(作为PowerSock的 PSock.pas 单元使用Winsock作为导入单位)。



PSock.pas 中的StreamLn函数刚刚添加在调用传递的 TStream 参数的 TStream.WriteBuffer 方法之前,将该字符串的CRLF序列传递为参数。 p>

$ c> PSock.pas


I am trying to compile my program but I am getting this error:

Undeclared indentifier 'StreamLn'

i even tried to download PSock.dcu and put it into the library but it doesnt compile, it looks like its compactible with delphi 5,

unit ResourceInfo;

interface

uses
  Classes, SysUtils, Windows;

type
  TResourceInfo = class;

  TDfmMode = ( dfmData, dfmResource, dfmASCII, dfmBinary);

  TDfm = class
  private
    FOwner: TResourceInfo;
    FName: string;
    FData: TStream;

    procedure SetName(const Value: string);
    procedure SetOwner(const Value: TResourceInfo);

  public
    constructor Create(AOwner: TResourceInfo);
    destructor Destroy; override;

    function SaveToFile(FileName: TFileName; Mode: TDfmMode): Boolean;

    property Data: TStream read FData;
    property Name: string read FName write SetName;
    property Owner: TResourceInfo read FOwner write FOwner;
  end; {TDfm}

  TResourceInfo = class(TComponent)
  private
    FActive: Boolean;
    FDfms: TList;
    FExeFileName: TFileName;
    FModule: THandle;
    FOnActivate: TNotifyEvent;
    FOnDeactivate: TNotifyEvent;

    procedure SetExeFileName(const Value: TFileName);
    procedure SetActive(const Value: Boolean);
    function  GetDfms(Index: Cardinal): TDfm;
    function  GetDfmCount: Cardinal;

  protected
    procedure Clear;

  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;

    function  AddDfm(const Name: string; AData: TMemoryStream): Integer;
    procedure DeleteDfm(const Name: string);
    property  DfmCount: Cardinal read GetDfmCount;
    property  Dfms[Index: Cardinal]: TDfm read GetDfms;
    procedure EnumDfmNames;
    property  Module: THandle read FModule;

  published
    property Active: Boolean read FActive write SetActive;
    property ExeFileName: TFileName read FExeFileName write SetExeFileName;

    property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
    property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
  end; {TResourceInfo}

procedure Register;

implementation

uses
 Winsock;

resourcestring
  rsErrorLoadingExeFile = 'An error ocurred loading file %s, it may not be an executable module';

procedure Register;
begin
  RegisterComponents('+HCU', [TResourceInfo]);
end; {Register}

{ TResourceInfo }

function TResourceInfo.AddDfm(const Name: string; AData: TMemoryStream): Integer;
var
  FDfm: TDfm;
begin
  FDfm := TDfm.Create(Self);
  FDfm.Name := Name;
  FDfm.Data.Size := AData.Size;
  FDfm.Data.Seek(0, 0);
  AData.Seek(0, 0);
  FDfm.Data.CopyFrom(AData, AData.Size);
  Result := FDfms.Add(FDfm);
end; {TResourceInfo.AddDfm}

constructor TResourceInfo.Create(AOwner: TComponent);
begin
  inherited;

  FActive := False;
  FDfms := TList.Create;
  FModule := 0;
end; {TResourceInfo.Create}

destructor TResourceInfo.Destroy;
begin
  Clear;
  FDfms.Free;

  inherited;
end; {TResourceInfo.Destroy}

function CB_EnumDfmNameProc(hModule: THandle; lpszType, lpszName: PChar; lParam: Integer): Boolean; stdcall;
var
  ms: TMemoryStream;
  rs: TResourceStream;
  Buffer: array of Byte;
begin
  with TResourceInfo(lParam) do
    begin
      rs := TResourceStream.Create(TResourceInfo(lParam).Module, lpszname, lpszType);
      try
        ms := TMemoryStream.Create;
        try
          try
            SetLength(Buffer, 4);
            rs.Read(Buffer[0], SizeOf(Buffer));
            if string(Buffer) = 'TPF0' then
              begin
                rs.Seek(0, 0);
                ObjectBinaryToText(rs, ms);
                ms.Seek(0, 0);
                AddDfm(StrPas(lpszName), ms);
              end;
          except
            raise;
          end;
        finally
          ms.Free;
        end;
      finally
        rs.free;
      end;
    end;

  Result := True;
end; {CB_EnumDfmNameProc}

procedure TResourceInfo.EnumDfmNames;
begin
  if FModule > 0 then
    EnumResourceNames(FModule, RT_RCDATA, @CB_EnumDfmNameProc, Integer(Self));
end; {TResourceInfo.EnumDfmNames}

procedure TResourceInfo.DeleteDfm(const Name: string);
var
  i: Cardinal;
begin
  if FDfms.Count > 0 then
    for i := Pred(FDfms.Count) downto 0 do
      if UpperCase(TDfm(FDfms[i]).Name) = UpperCase(Name) then
        begin
          FDfms.Delete(i);
          Break;
        end;
end; {TResourceInfo.DeleteDfm}

procedure TResourceInfo.SetActive(const Value: Boolean);
begin
  if FActive <> Value then
    begin
      if Value then
        begin
          if FModule > 0 then
            FreeLibrary(FModule);

            (* LOAD_LIBRARY_AS_DATAFILE
               If this value is given, the function does a simple mapping of the file into the
               address space. Nothing is done relative to executing or preparing to execute the
               code in the mapped file. The function loads the module as if it were a data file.
               You can use the module handle that the function returns in this case with the Win32
               functions that operate on resources. Use this flag when you want to load a DLL in
               order to extract messages or resources from it, and have no intention of executing
               its code.If this value is not given, the function maps the file into the address
               space in the manner that is normal for an executable module. The behavior of the
               function is then identical to that of LoadLibrary in this regard. *)

          FModule := LoadLibraryEx(PChar(FExeFileName), 0, LOAD_LIBRARY_AS_DATAFILE);
          if not (FModule >= 32) then
            raise Exception.CreateFmt(rsErrorLoadingExeFile, [FExeFileName]);
          if Assigned(FOnActivate) then
            FOnActivate(Self);
        end
      else
        begin
          Clear;
          if FModule > 0 then
            begin
              FreeLibrary(FModule);
              FModule := 0;
            end;
          if Assigned(FOnDeactivate) then
            FOnDeactivate(Self);
        end;
      FActive := Value;
    end;
end; {TResourceInfo.SetActive}

procedure TResourceInfo.SetExeFileName(const Value: TFileName);
begin
  if FExeFileName <> Value then
    FExeFileName := Value;
end; {TResourceInfo.SetExeFileName}

function TResourceInfo.GetDfms(Index: Cardinal): TDfm;
begin
  Result := TDfm(FDfms[Index]);
end; {TResourceInfo.GetDfms}

function TResourceInfo.GetDfmCount: Cardinal;
begin
  Result := FDfms.Count;
end; {TResourceInfo.GetDfmCount}

procedure TResourceInfo.Clear;
begin
  if FDfms.Count > 0 then
    while FDfms.Count > 0 do
      FDfms.Delete(0);
end; {TResourceInfo.Clear}

{ TDfm }

constructor TDfm.Create(AOwner: TResourceInfo);
begin
  inherited Create;

  FData := TMemoryStream.Create;
  FName := '';
  SetOwner(AOwner);
end; {TDfm.Create}

destructor TDfm.Destroy;
begin
  FData.Free;
  inherited;
end; {TDfm.Destroy}


function TDfm.SaveToFile(FileName: TFileName; Mode: TDfmMode): Boolean;

  function EndOfStream(Stream: TStream): Boolean;
  begin
    with Stream do
      Result := Position = Size;
  end; {EndOfStream}

var
  fs: TFileStream;
  ms: TMemoryStream;
  s: string;
  i, j: Byte;
begin
  fs := TFileStream.Create(FileName, fmCreate or fmShareExclusive);
  try
    FData.Seek(0, 0);

    case Mode of
      dfmASCII:
        begin
          ms := TMemoryStream.Create;
          try
            s := FName + ' RCDATA' + #13#10 + '{';
            StreamLN(fs, s);

            ObjectTextToBinary(FData, ms);
            ms.Seek(0, 0);

            while not EndOfStream(ms) do
              begin
                s := '''';

                for i := 0 to 15 do
                  begin
                    if ms.Read(j, SizeOf(j)) = 0 then
                      Break;
                    s := Concat(s, Format('%2.2x', [j]));
                    if (i = 15) or EndOfStream(ms) then
                      s := Concat(s, '''')
                    else
                      s := Concat(s, ' ');
                  end;

                if EndOfStream(ms) then
                  s := Concat(s, #13#10 + '}');
                StreamLN(fs, s);
              end;

          finally
            ms.Free;
          end;
        end;

      dfmBinary:
        ObjectTextToBinary(FData, fs);
    end;

  finally
    fs.Free;
  end;
end; {TDfm.SaveToFile}

procedure TDfm.SetName(const Value: string);
begin
  if FName <> Value then
    FName := Value;
end; {TDfm.SetName}

procedure TDfm.SetOwner(const Value: TResourceInfo);
begin
  FOwner := Value;
end; {TDfm.SetOwner}

end.

How can I declare it successfully?

解决方案

Appears to me that WinSock unit does not have an StreamLn function (as PowerSock's PSock.pas unit uses Winsock as imported unit).

The StreamLn function in PSock.pas just adds an CRLF sequence to the string passed as parameter before calling the TStream.WriteBuffer method of the passed TStream parameter.

Here's the google cache snapshot from the Powersock's source code of PSock.pas

这篇关于如何正确声明StreamLn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 11:52