把你的代码贴出来,要不改用string

解决方案 »

  1.   

    我通常是这样的:
    procedure FormatShortString(var s:shortstring);
    var
      li_len : integer;
    begin
      li_len := length(s);
      move(s[1],s[0],li_len);
      s[li_len] := #0;
    end;
    function func_test(out msg : shortstring) : shortstring;stdcall
    begin
       .......
       msg := 'message';
       result := 'ok';
       formatShortSTring(msg);
       formatShortString(result)
    end;
      

  2.   

    函数调用方式是否一样。即dll和调用dll的函数是否都声明了stdcall?
      

  3.   

    我通常是这样的:
    procedure FormatShortString(var s:shortstring);
    var
      li_len : integer;
    begin
      li_len := length(s);
      move(s[1],s[0],li_len);
      s[li_len] := #0;
    end;
    function func_test(out msg : shortstring) : shortstring;stdcall
    begin
       .......
       msg := 'message';
       result := 'ok';
       formatShortSTring(msg);
       formatShortString(result)
    end;
      

  4.   

    动态库中用pChar类型,调用的时候用pChar(str:String);
      

  5.   

    function GetFieldValue(FieldName: String;WebContext: String): String;
    var
      a: Widestring;
      CurrPos: Integer;
      StartPos: Integer;
      EndPos: Integer;
      Count: Integer;
      FieldValue: string;
      FieldSize: Integer;
      TotalSize: Integer;
      I,J: Integer;
      FlagChar: WideChar;
    begin
      TotalSize := length(WebContext);
      CurrPos := pos(FieldName,WebContext);
      if CurrPos < 1 then
      begin
        Result := '';
        Exit;
      end
      else
        CurrPos := CurrPos + 1;
      Count := 0;
      while Count <> 4 do
      begin
        if WebContext[CurrPos] = '>' then Count := Count + 1;
        CurrPos := CurrPos + 1;
      end;
      StartPos := CurrPos;
      FlagChar := ' ';
      CurrPos := CurrPos - 1;
      while True do
      begin
        CurrPos := CurrPos + 1;
        if CurrPos > TotalSize then
        begin
          Result := '';
          Exit;
        end;
        if WebContext[CurrPos] = '<' then
        begin
          FlagChar := '<';
          Continue;
        end;
        if (WebContext[CurrPos] = 'F') and (FlagChar = '<') then
        begin
          FlagChar := 'F';
          Continue;
        end;
        if (WebContext[CurrPos] = 'O') and (FlagChar = 'F') then
        begin
          FlagChar := 'O';
          Continue;
        end;
        if (WebContext[CurrPos] = 'N') and (FlagChar = 'O') then
        begin
          FlagChar := 'N';
          Continue;
        end;
        if (WebContext[CurrPos] = 'T') and (FlagChar = 'N') then
        begin
          FlagChar := 'T';
          Continue;
        end;
        if (WebContext[CurrPos] = '>') and (FlagChar = 'T') then Break;
      end;//end while
      EndPos := CurrPos - 7;
      FieldSize := EndPos - StartPos + 1;
      SetLength(FieldValue,FieldSize);
      J := 1;
      for I := StartPos to EndPos do
      begin
        FieldValue[J] := WebContext[I];
        J := J + 1;
      end;
      Result := FieldValue;
    end;function ReplaceString(ReplacedChar,Replace: string;WebContext: string): string;
    var
      CurrPos: Integer;
      ReplacedSize: Integer;
      TotalSize: Integer;
    begin
      Result := WebContext;
      TotalSize := length(WebContext);
      ReplacedSize := length(ReplacedChar);
      while True do
      begin
        CurrPos := Pos(ReplacedChar,WebContext);
        if CurrPos < 1 then Break;
        WebContext := copy(WebContext,1,CurrPos - 1) + Replace
                    + copy(WebContext,CurrPos + ReplacedSize,TotalSize - CurrPos - ReplacedSize + 1);
      end;
      Result := WebContext;
    end;function GetEmail(email: string): string;
    var
      CurrPos: Integer;
      TotalSize: Integer;
    begin
      TotalSize := length(email);
      CurrPos := pos('>',email);
      if CurrPos >= 1 then
        email := copy(email,Currpos + 1,TotalSize - CurrPos);
      CurrPos := pos('<',email);  if CurrPos >= 1 then
        email := copy(email,1,CurrPos - 1);
      Result := email;end;
    function GetWeb(WebContext: PChar): PChar;stdcall;
    var
      FieldName: string;
      WebString: string;
      MiddleString: string;
      ResultString: string;
      TotalSize: Integer;
      //sabc : Integer;
    begin
      WebString := WideCharToString(WebContext);
      FieldName := '>姓&nbsp;&nbsp;&nbsp; '+ SwapLine + '      名<';
      ResultString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));  FieldName := '>性&nbsp;&nbsp;&nbsp; '+ SwapLine + '      别<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>年&nbsp;&nbsp;&nbsp; '+ SwapLine + '      龄<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>联系地址<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>邮政编码<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>电&nbsp;&nbsp;&nbsp; '+ SwapLine + '      话<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>电子邮件<';
      MiddleString := GetEmail(ReplaceString(Space,' ',GetFieldValue(FieldName,WebString)));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>工作单位<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>信件编号<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>发信时间<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>来信主题<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;//}  FieldName := '>具体内容<';
      MiddleString := ReplaceString('<BR>',' ',ReplaceString   (Space,' ',GetFieldValue(FieldName,WebString)));
      ResultString := ResultString + SwapLine + MiddleString;
      FieldName := '>信件状态<';
      MiddleString := ReplaceString(Space,' ',GetFieldValue(FieldName,WebString));
      ResultString := ResultString + SwapLine + MiddleString;  FieldName := '>处理意见<';
      MiddleString := ReplaceString('<BR>',SwapLine,ReplaceString(Space,' ',GetFieldValue(FieldName,WebString)));
      ResultString := ResultString + SwapLine + MiddleString; //}
      
      Result := PChar(ResultString);
    end;