Solved

Nedd help on this code!

Posted on 1997-07-10
4
137 Views
Last Modified: 2010-04-06
Well the question is:
I have a TListView component on my form that displays directories. I have an OnEdeted event to rename the file. Well when i rename it i get an access violation error after which the file is renamed. I can not get it. Delphi does not show breakepoint, because my mashine hangs up when delphi gets this error:-)
//Code start
var
        dir: string;
begin
        if Item=nil then Exit;
        if Item.Caption=S then Exit;
        dir:=GetCurrentDir;
        if dir[Length(dir)]<>'\' then dir:=dir+'\';
        RenameFile(dir+Item.Caption,dir+s);
        UpdateLocalListing; // updating directory listing
//End code
0
Comment
Question by:Alexei_A
4 Comments
 
LVL 1

Expert Comment

by:kevinb062397
ID: 1338548
Have you tried using {$I-} around the renamefile()?
...
{$I-}
RenameFile(dir+Item.Caption,dir+s);
{$I+}
if IOResult <> 0 then
Showmessage('File was not renamed.')
else
Showmessage('File was renamed successfully.')
...

This will not fix the code itself but it will help in isolating the error down to which line is causing the problem.

You could put a sleep(500) between the rename and update lines to give the system time to change the name before the redraw.

What does the UpdateLocalListing do other than update the items?



0
 
LVL 4

Expert Comment

by:erajoj
ID: 1338549
Can you send in "UpdateLocalListing"?
There should be no problem with the code you sent in.
This is lame, but, have you tried "SysUtils.RenameFile..."
so there's nothing colliding... %-6.

/// John

0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 50 total points
ID: 1338550
"Alexei A" - This code is OK but you probably have component for file list.When You rename directory Then you must change directory for this file list too !

"kevinb" - RenameFile is function so result give you information if file is renamed or no. IOResult is bad (nothing hapened)
0
 

Author Comment

by:Alexei_A
ID: 1338551
But i found that it was possible to
do it in try ... finally
var
                        dir: string;
                    begin
                         try
                        if Item=nil then Exit;
                        if Item.Caption=S then Exit;
                        dir:=GetCurrentDir;
                        if dir[Length(dir)]<>'\' then dir:=dir+'\';
                        RenameFile(dir+Item.Caption,dir+s);
                         finally
                        UpdateLocalListing; // updating directory
listing
end;
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question