Solved

Nedd help on this code!

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

9 Experts available now in Live!

Get 1:1 Help Now