Solved

Nedd help on this code!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LAN or WAN ? 11 105
Dynamically Created Query 3 69
Delphi Seattle StructureView color 1 21
"Could not obtain OLE control window handle" under Delphi XE8 8 16
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 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