Solved

Reading open files

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

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
When I am typing into a TEdit last word repeats 7 158
Performance of SQL statement 37 137
Base1 Encode/Decode 3 85
Problem working with dynamic array - help 2 35
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…

740 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