function trac(source:widestring;count:integer):widestring;
var
  I : Integer ;
  temp_s : string ;begin
  temp_s := '';
  for I := 1 to count do
  temp_s := temp_s + string(source)[i];
  if (ord(string(temp_s)[count]) >256 ) and (ord(string(temp_s)[count-1]) <256 )then
  delete(temp_s,count,1);
  trac := temp_s ;end ;

解决方案 »

  1.   

    function TForm1.trac(source:string;count:integer):string;
    var
      s:string;
    begin
      result := source;
      s:=source[count];
      if s>#127 then
        result := copy(source,1,count-1);
    end;
      

  2.   

    function trac(source:widestring;count:integer):widestring;
    var
      Str: AnsiString ;
    begin
      Str := Copy(AnsiString(source), 1, count);
      if Ord(Str[Length(Str)])>127 then
        Result := Copy(Str, 1, Length(Str) - 1)
      else
        Result := Str;
    end;
      

  3.   

    function trac(source:widestring;count:integer):widestring;
    var
      str: string;
    begin
      str := string(source);
      SetLength(str,count);
      result := widestring(str);
    end;