?
Solved

Reading open files

Posted on 1997-03-25
4
Medium Priority
?
193 Views
Last Modified: 2010-05-18
I wrote a program in Delphi2 that needs to read data that has been appended to the executable of this program. It is not able to read data from the executable when it's running. I guess this is because the file is open and denies any access to itself. Is there any workaround for this?
As far as I remember this has been possible with Pascal in DOS...
0
Comment
Question by:tier
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
mheacock earned 200 total points
ID: 1334954
This may or may not work...but you might try copying it to
a temporary directory, reading from it, then deleting it.

My guess is that it won't work (in which case reject my answer),
but it is worth a try.
0
 
LVL 1

Author Comment

by:tier
ID: 1334955
No, this does not work...
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334956
This should work:

    Use the Win32 API function CreateFile as follows:

     //open main file
    handle := CreateFile(pchar(exepath), generic_read,
                         file_share_read, nil, open_existing,
                         FILE_ATTRIBUTE_NORMAL, 0);

where "exepath" is an ansistring containing the path to the executable you wish you open.
0
 
LVL 1

Expert Comment

by:slp
ID: 1334957
I'm curious as to how you appended the data to the executable.  One "Windows approved" way of doing something like this that is supported by the API is to add your data as a resource, then you don't have to worry about finding the file, file locking, sharing violations or anything else of the sort.

SLP

0

Featured Post

Industry Leaders: 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

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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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