Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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