Solved

How to 'right' this 'wrong' function???

Posted on 2004-04-02
5
148 Views
Last Modified: 2010-04-05
Hi all!! I'm trying to compile this package which should be no problem in D7, at least that is what I was told. Compiling however halts at an early stage and I can't circumvent this. I know, cause I tried...;(

This function causes the problem with its StrReplace > something I could not find in delphi help (D7) and also something I couldn't 'fix'.
Anyone dare to try??
The error message states that either 'a file' already is in use or that it is readonly (which it is NOT) or it refers to my harddisk being damaged. Out of these three I would go for the first > so I went and went but I couldn't find a file used, that was already in use. (this function is part of the actor creator kit which helps you create a custom .aad and afterwards .aal file to respresent an office assistant like creature.....)

 function CreateProject(LibName, ResName: String): String;
  var
    I: Integer;
    F: TextFile;
    ResFileNameOnly: String;
    LibNameOnly, LibExtOnly: String;
  begin
    ResFileNameOnly := ExtractFileName(ResName);
    LibNameOnly := ChangeFileExt(ExtractFileName(LibName), '');
    LibExtOnly := ReplaceStr(ExtractFileExt(LibName), '.', '');
    Result := ChangeFileExt(LibName, '.dpr');
    AssignFile(F, Result);
    Rewrite(F);
    try
      for I := 0 to LibSource.Strings.Count-1 do
        if Pos('%f', LibSource.Strings[I]) <> 0 then
          WriteLn(F, ReplaceStr(LibSource.Strings[I], '%f', LibNameOnly))
        else if Pos('%r', LibSource.Strings[I]) <> 0 then
          WriteLn(F, ReplaceStr(LibSource.Strings[I], '%r', ResFileNameOnly))
        else if Pos('%e', LibSource.Strings[I]) <> 0 then
          WriteLn(F, ReplaceStr(LibSource.Strings[I], '%e', LibExtOnly))
        else
          WriteLn(F, LibSource.Strings[I]);
    finally
      CloseFile(F);
    end;
  end;

My regards to all-o-ya!! Keep up da good work!!

Peter

(ps correcting the problem and providing a functional replacement equals the points ofcourse;)
0
Comment
Question by:PeterdeB
  • 3
5 Comments
 

Author Comment

by:PeterdeB
ID: 10744982
Ooeps > ReplaceStr that is instead of StrReplace;)
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745043
StringReplace ?
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 250 total points
ID: 10745062
Have you tried replacing this with the StringReplace function in Delphi?

StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;

eg:

WriteLn(F,StringReplace(LibSource.Strings[I], '%f', LibNameOnly, [rfReplaceAll]));

Just a thought,
Russell

0
 

Author Comment

by:PeterdeB
ID: 10746804
Hi Mokule and rllibby! Yes I tried but couldn't get this thing working anyway > I will now try again (using your response Russell)

Thanks in advance for the replies!!

I will get back to this,

Peter
0
 

Author Comment

by:PeterdeB
ID: 10751399
Hi all,

Thanks to both of you for assisting me > Russell you get the points cause I consider your answer to be complete even though Mokule responded before you did (just to explain why ....). I had already thought about the StringReplace but failed to implement it accordingly even though it does seem logics now, ofcourse this was after Russell provided the solution.

My regards and appreciation, Peter

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

23 Experts available now in Live!

Get 1:1 Help Now