编译报错:[Error] Unit1.pas(203): Incompatible types: 'Array' and 'PAnsiChar'(50分)

  • 主题发起人 主题发起人 zylsoft
  • 开始时间 开始时间
Z

zylsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
编译报错:[Error] Unit1.pas(203): Incompatible types: 'Array' and 'PAnsiChar'

type
PClient = ^TClient;
TClient=record
IP : array[1..20] of char;
DNS : array[1..20] of char;
Thread : Pointer;
end;



var NewClient: PClient;
begin

NewClient.IP := pchar('127.0.0.1');

end;

把pchar换成pansichar还是报一样的错误
 
你IP是数组啊,pansichar,pchar是指针,类型不匹配的。
把ip定义成string,
 
StrPCopy(NewClient.IP ,'127.0.0.1');
 
PCTKP_HEAD_tag = ^TCTKP_HEAD_tag;
TCTKP_HEAD_tag = record
Command_ID: array[1..20] of char;
end;
type
P_init =^T_init;
T_init = record
head: TCTKP_HEAD_tag;
body: TCTKP_CONNECT_tag;
end;


var Ninit:t_init;
begin
Ninit.head.Command_ID:=strpcopy('命令');


也是不行呀!!
 
刚写的,你试试:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}


procedure StrCopy(pDest : PChar; pSource : string; aLen : integer);
var
i : integer;
begin
FillMemory(pDest, aLen, 0);
for i := 0 to aLen - 1 do
pDest := pSource[i + 1];
end;

procedure TForm1.Button1Click(Sender: TObject);
var
tmpArr : array[0..3] of Char;
begin
StrCopy(tmpArr, 'abcd', 4);
showmessage(string(tmpArr));
end;

end.
 
后退
顶部