var
s:string;h:thandle;
begin
setlength(s,10);
if opendialog1.Execute then
begin
  h:=fileopen(opendialog1.Filename,fmopenread);
  fileread(h,s,10);
  fileclose(h);
  showmessage(s);
end;
end;运行期错误。????

解决方案 »

  1.   

    结构是可以,但是只是不会出错,但是读出来的是空的:
    type
      TMyRec=record
        i:integer;
        c:char;
        a:array[1..10] of char;
        s:string;
      end;
    ///////////////
    var
    s:array[1..10] of char;
    h:thandle;
    a:tmyrec;
    begin
    //setlength(s,10);if opendialog1.Execute then
    begin
      h:=fileopen(opendialog1.Filename,fmopenread);
      fileread(h,a,10);
      fileclose(h);
      msg(a.s);
    end;
    end;
      

  2.   

    function FileRead(Handle: Integer; var Buffer; Count: Integer): Integer;
    0A
    其中 Buffer 应该是指针,不能是具体变量
    —————————————————————————————————
    MaximStr := '宠辱不惊,看庭前花开花落,去留无意;
                 毁誉由人,望天上云卷云舒,聚散任风。';
    if Not Assigned(I) then
      I := TI.Create(Nil);
    I.Maxim := MaximStr;
    —————————————————————————————————
           
      

  3.   

    如果用结构,改为:a:tmyrec;if opendialog1.Execute then
    begin
      h:=fileopen(opendialog1.Filename,fmopenread);
      fileread(h,a.a,10);
      fileclose(h);
      msg(a.s);
    end;
    —————————————————————————————————
    MaximStr := '宠辱不惊,看庭前花开花落,去留无意;
                 毁誉由人,望天上云卷云舒,聚散任风。';
    if Not Assigned(I) then
      I := TI.Create(Nil);
    I.Maxim := MaximStr;
    —————————————————————————————————
           
      

  4.   

    不是指针也可以呀,比如
    fileread(h,a.c{或者a.i},100)都可以呀。a:array of char;if opendialog1.Execute then
    begin
      h:=fileopen(opendialog1.Filename,fmopenread);
      fileread(h,a,10);
      fileclose(h);
      
    end;里面的a不是指针?
      

  5.   

    Buffer是首地址

    var                                首地址
      P: Pointer;                      P^
      P: PChar                         P^
      //只要是指针类型就是              P^
      S: string                        S[1];
      Arr: array [0..10] of Char;      Arr[0] or Arr
      Arr: array [0..10] of TDataRecord Arr[0] or Arr
      //只要是array 类型就是           Arr[0] or Arr
     
      

  6.   

    FileRead的第二个参数要求是已分配地址的变量下例是正确的:
    var s: PChar;
      h:THandle;
    begin
      GetMem(s,256);  //分配地址,不能少
      h := FileOpen('H:\Delphi\函数.txt',fmOpenRead);
      FileRead(h,s^,256);  //^不能少,取地址
    end;
    出现运行骑错误,一般都是没有分配地址。
    —————————————————————————————————
    MaximStr := '宠辱不惊,看庭前花开花落,去留无意;
                 毁誉由人,望天上云卷云舒,聚散任风。';
    if Not Assigned(I) then
      I := TI.Create(Nil);
    I.Maxim := MaximStr;
    —————————————————————————————————
           
      

  7.   

    FileRead的第二个参数要求是已分配地址的变量的地址下例是正确的:
    var s: PChar;
      h:THandle;
    begin
      GetMem(s,256);  //分配地址,不能少
      h := FileOpen('H:\Delphi\函数.txt',fmOpenRead);
      FileRead(h,s^,256);  //^不能少,取地址
    end;
    出现运行骑错误,一般都是没有分配地址。
    —————————————————————————————————
    MaximStr := '宠辱不惊,看庭前花开花落,去留无意;
                 毁誉由人,望天上云卷云舒,聚散任风。';
    if Not Assigned(I) then
      I := TI.Create(Nil);
    I.Maxim := MaximStr;
    —————————————————————————————————