Solved

Nedd help on this code!

Posted on 1997-07-10
4
134 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now