Solved

Reading open files

Posted on 1997-03-25
4
186 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 100 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

736 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