Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Nedd help on this code!

Posted on 1997-07-10
4
Medium Priority
?
145 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 150 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

971 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