var 
str:string
pc:pchar;str:=format( , );
pc:=pchar(str);///这个丢字符了,而且没有规律转为pchar的目的是为了返回值兼容c

解决方案 »

  1.   

    function a():pchar;
    var 
    str:string 
    pc:pchar; 
    begin
    str:=format( , ); ///结果1
    result:=pchar(str);
    end;
    ------------------- 
    procedure b;
    var str2:string;
    begin
    str2:=a(); //不行,不等于结果1
    str2:=strpas(a());//或者这个,还是不行
    end;
      

  2.   

    PAS:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
      function a():pchar;
      var
        str:string;
        pc:pchar;
      begin
        str:= '1';
        result:=pchar(str);
      end;var str1,str2:string;
    begin
       str1:=a(); //不行,不等于结果1
       str2:=strpas(a());//或者这个,还是不行
       edit1.text := Str1;
       edit2.text := str2;end;end.
    DRM:
    object Form1: TForm1
      Left = 192
      Top = 114
      Width = 696
      Height = 480
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object Button1: TButton
        Left = 272
        Top = 288
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 0
        OnClick = Button1Click
      end
      object Edit1: TEdit
        Left = 272
        Top = 112
        Width = 121
        Height = 21
        TabOrder = 1
        Text = 'Edit1'
      end
      object Edit2: TEdit
        Left = 288
        Top = 152
        Width = 121
        Height = 21
        TabOrder = 2
        Text = 'Edit2'
      end
    end
    跟你上面的代码一模一样,Edit1,edit2 都返回'1';只想问你的FORMAT出来的确实是“1“吗??调试了没有?