0
function getFileName(fileDir : string) : string;
var
fileName : string;
tempNum, i : integer;
tempChar : char;
begin
tempNum := 0;
  for I := Length(fileDir) downto 0 do
  begin
    tempNum := tempNum + 1;
    tempChar := fileDir[I-1];
    if tempChar = '\' then
      break;
  end;

  Result := RightStr(fileDir, tempNum);

end;

It shows that acces violation is in this line:

tempChar := fileDir[I-1];

What does it mean? And why there is a such a problem?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by FlamingClaw
0

listen this code,I created a form,put one editbox and a button
edit1.text set to 'c:\bp\bin\turbo.exe'
and the button's code can be see below

procedure TForm1.Button1Click(Sender: TObject);
      function getFileName(fileDir : string) : string;
      var
      fileName : string;
      tempNum, i : integer;
      tempChar : char;
      tempname:string;(*store the file name only*)
      begin
            tempNum := 0;
            tempname:='';
            for I := Length(fileDir) downto 0 do
            begin
               tempNum := tempNum + 1;
               tempChar := fileDir[I];
               tempname:=tempchar+tempname;
               if (filedir[i-1] = '\') then break;
           end;
       Result := tempname;
     end;
begin
    showmessage(getfilename(edit1.text));(*show the result*)
 end;
(*result is turbo.exe*)

good luck!
by FlamingClaw 2010.03.17.Hungary.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.