Solved

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

Posted on 2004-04-02
5
158 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

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

Suggested Solutions

Title # Comments Views Activity
Process Javascript errors with Delphi TWebBrowser 1 208
When I am typing into a TEdit last word repeats 7 161
Printing problem 2 111
How to build JSON File in Delphi 6 3 71
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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