?
Solved

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

Posted on 2004-04-02
5
Medium Priority
?
164 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
[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
  • 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month15 days, left to enroll

771 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