Recent

Author Topic: Copy2Symb and Copy2SymbDel Problem  (Read 825 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Copy2Symb and Copy2SymbDel Problem
« on: August 28, 2022, 06:57:07 am »
The first comment line, line 1 is after execution of line 3.
The second comment line, Line 2 is after execution of line 5
At the end of the procedure  sERRORS = nil and S2PARSE is unchanged.
The ReplaceStr and Copy2SymbDel didn't work.
Both sERRORS and S2PARSE ard declared as global VARs.

Don't understand

Thanks

Code: Pascal  [Select][+][-]
  1.    Case AItem of               //sERRORS ='function DbgS(a: TAnchorKind ): string; overload; function DbgS(Anchors: TAnchors ): string; overload; function DbgS(a: TAlign ): string; overload; function DbgS(a: TAnchorKind; Side: TAnchorSideReference ): string; overload; function DbgS(p: TControlAutoSizePhase ): string; overload; function DbgS(Phases: TControlAutoSizePhases ): string; overload; function DbgS(cst: TControlStyleType ): string; overload; function DbgS(cs: TControlStyle ): string; overload; Function result The string representing the given parameter(s). Arguments Phases All elements in this set will be shown as a comma-separated list. Errors [The parameters should have unique names, for every type]'
  2.     'Errors'      : begin      //sERRORS ='function DbgS(a: TAnchorKind ): string; overload; function DbgS(Anchors: TAnchors ): string; overload; function DbgS(a: TAlign ): string; overload; function DbgS(a: TAnchorKind; Side: TAnchorSideReference ): string; overload; function DbgS(p: TControlAutoSizePhase ): string; overload; function DbgS(Phases: TControlAutoSizePhases ): string; overload; function DbgS(cst: TControlStyleType ): string; overload; function DbgS(cs: TControlStyle ): string; overload; Function result The string representing the given parameter(s). Arguments Phases All elements in this set will be shown as a comma-separated list. Errors [The parameters should have unique names, for every type]'
  3.                      sErrors:=S2PARSE;
  4.                      S2PARSE:=ReplaceStr(sErrors,'Errors','|Errors:');
  5.                      S2PARSE:=Copy2SymbDel(sErrors,'|');
  6.  
  7. //S2PARSE ='function DbgS(a: TAnchorKind ): string; overload; function DbgS(Anchors: TAnchors ): string; overload; function DbgS(a: TAlign ): string; overload; function DbgS(a: TAnchorKind; Side: TAnchorSideReference ): string; overload; function DbgS(p: TControlAutoSizePhase ): string; overload; function DbgS(Phases: TControlAutoSizePhases ): string; overload; function DbgS(cst: TControlStyleType ): string; overload; function DbgS(cs: TControlStyle ): string; overload; Function result The string representing the given parameter(s). Arguments Phases All elements in this set will be shown as a comma-separated list. Errors [The parameters should have unique names, for every type]'
  8.  
  9.  
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: Copy2Symb and Copy2SymbDel Problem
« Reply #1 on: August 28, 2022, 11:58:11 am »
Don't understand
Wrong name variable ?

Code: Pascal  [Select][+][-]
  1.  sErrors:=S2PARSE;
  2.  S2PARSE:=ReplaceStr(sErrors,'Errors','|Errors:');
  3.  S2PARSE:=Copy2SymbDel(S2PARSE,'|');
  4.  

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Copy2Symb and Copy2SymbDel Problem
« Reply #2 on: August 28, 2022, 04:15:25 pm »
Don't understand the reply. The actual sErrors string is shown with Errors.

Where is the wrong variable?
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Copy2Symb and Copy2SymbDel Problem
« Reply #3 on: August 28, 2022, 04:51:20 pm »
A little misuse of the Copy2SymDel..

Thousand partially corrected it but not totally.

That function will delete up to the marker but it is also being used as a return so in end all you have is the copy up to the first '|' and the rest of the string is gone.

 That function needs to use a different return string so the function can property delete the return from the input string so the remaining string can be scanned again for more '|'.

The only true wisdom is knowing you know nothing

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: Copy2Symb and Copy2SymbDel Problem
« Reply #4 on: August 28, 2022, 05:59:03 pm »
Don't understand the reply. The actual sErrors string is shown with Errors.

Where is the wrong variable?
Line 3.

You have 3 line:
1 - copy S2PARSE -> sERRORS
2 - S2PARSE is replace "Errors" make "|Errors:"
3 - Copy2SymDef is copy all character before "|".

line 3 you code is copy all character before "|" string sErrors. But you code not replace sErrors but S2PARSE

better:
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   strutils;
  7.  
  8. var
  9.   S2PARSE:string='hello this is Errors and get for you';
  10.   sErrors:string;
  11. begin
  12.   writeln('S2PARSE = "',S2PARSE,'"');
  13.   sErrors:=S2PARSE;
  14.   writeln('sErrors = "',sErrors,'"');
  15.   S2PARSE:=ReplaceStr(sErrors,'Errors','|Errors:');
  16.   writeln('S2PARSE = "',S2PARSE,'"');
  17.   S2PARSE:=Copy2SymbDel(S2PARSE,'|');
  18.   writeln('S2PARSE = "',S2PARSE,'"');
  19. end.
  20.  

output:
Code: [Select]
S2PARSE = "hello this is Errors and get for you"
sErrors = "hello this is Errors and get for you"
S2PARSE = "hello this is |Errors: and get for you"
S2PARSE = "hello this is "

@jamie:
yes, is true but depend what user JLWest want. I can no see with example code.

@JLWest:
Jamie is write about parsing and do correct...then example look more:
Code: Pascal  [Select][+][-]
  1. program test2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   strutils;
  7.  
  8. var
  9.   S2PARSE:string='hello this is Errors and get Errors for you with Errors that can Errors or not Errors some time';
  10.   sErrors:string;
  11.   sSymDel:string;
  12. begin
  13.   writeln('S2PARSE = "',S2PARSE,'"');
  14.   sErrors:=S2PARSE;
  15.   writeln('sErrors = "',sErrors,'"');
  16.   S2PARSE:=ReplaceStr(sErrors,'Errors','|Errors:');
  17.   writeln('S2PARSE = "',S2PARSE,'"');
  18.   repeat
  19.     sSymDel:=Copy2SymbDel(S2PARSE,'|');
  20.     writeln('sSymDel = "',sSymDel,'"',' ':30-Length(sSymDel),'S2PARSE = "',S2PARSE,'"');
  21.   until sSymDel='';
  22. end
  23.  
output:
Code: [Select]
S2PARSE = "hello this is Errors and get Errors for you with Errors that can Errors or not Errors some time"
sErrors = "hello this is Errors and get Errors for you with Errors that can Errors or not Errors some time"
S2PARSE = "hello this is |Errors: and get |Errors: for you with |Errors: that can |Errors: or not |Errors: some time"
sSymDel = "hello this is "                S2PARSE = "Errors: and get |Errors: for you with |Errors: that can |Errors: or not |Errors: some time"
sSymDel = "Errors: and get "              S2PARSE = "Errors: for you with |Errors: that can |Errors: or not |Errors: some time"
sSymDel = "Errors: for you with "         S2PARSE = "Errors: that can |Errors: or not |Errors: some time"
sSymDel = "Errors: that can "             S2PARSE = "Errors: or not |Errors: some time"
sSymDel = "Errors: or not "               S2PARSE = "Errors: some time"
sSymDel = "Errors: some time"             S2PARSE = ""
sSymDel = ""                              S2PARSE = ""

How use Copy2SymbDel() is depend what want.
« Last Edit: August 28, 2022, 07:11:07 pm by Thausand »

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Copy2Symb and Copy2SymbDel Problem
« Reply #5 on: August 29, 2022, 12:04:11 am »
There is a misconception somewhere, probably me.
Code: Pascal  [Select][+][-]
  1.  
  2. sSeeAlso = 'function FutureValue(ARate: Float; NPeriods: Integer; APayment: Float; APresentValue: Float; APaymentTime: TPaymentTime ): Float; Description FutureValue calculates the future value of an investment (FV) in the cash flow formula.  See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value given the future value of an investment.
  3. sSeeAlso =See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value given the future value of an investment.
  4.  
  5. After execution of line 8.
  6.  
  7. Var  sSEEALSO, S2PARSE: String; {Global}
  8.  
  9.   sSEEALSO:=S2PARSE;
  10.   sSEEALSO:=ReplaceStr( sSEEALSO, 'See also' , '|See also');
  11.   S2PARSE:=Copy2SymbDel( sSEEALSO, '|');
  12.  
  13. Final results: Which is pretty much what I want.
  14.  
  15. S2PARSE:='function FutureValue(ARate: Float; NPeriods: Integer; APayment: Float; APresentValue: Float; APaymentTime: TPaymentTime ): Float; Description FutureValue calculates the future value of an investment (FV) in the cash flow formula.  
  16.   sSEEALSO:=See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value given the future value of an investment.
  17.  
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: Copy2Symb and Copy2SymbDel Problem
« Reply #6 on: August 29, 2022, 12:13:13 pm »
There is a misconception somewhere, probably me.
I think you make mistake with name variable. Is ok.

Quote
sSeeAlso = 'function FutureValue(ARate: Float; NPeriods: Integer; APayment: Float; APresentValue: Float; APaymentTime: TPaymentTime ): Float; Description FutureValue calculates the future value of an investment (FV) in the cash flow formula.  See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value given the future value of an investment.
Quote
sSeeAlso =See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value given the future value of an investment.

Final results: Which is pretty much what I want.
Quote
S2PARSE:='function FutureValue(ARate: Float; NPeriods: Integer; APayment: Float; APresentValue: Float; APaymentTime: TPaymentTime ): Float; Description FutureValue calculates the future value of an investment (FV) in the cash flow formula. 

Quote
  sSEEALSO:=See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value

Then why make copy
Quote
sSEEALSO:=S2PARSE;
?

I think is name variable confusion.

If want final result then:
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   strutils;
  7.  
  8. var
  9.   sSEEALSO:string='function FutureValue(ARate: Float; NPeriods: Integer; APayment: Float; APresentValue: Float; APaymentTime: TPaymentTime ): Float; Description FutureValue calculates the future value of an investment (FV) in the cash flow formula.  See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value given the future value of an investment.';
  10.   S2PARSE:string;
  11. begin
  12.   sSEEALSO:=ReplaceStr(sSEEALSO,'See also','|See also');
  13.   S2PARSE:=Copy2SymbDel(sSEEALSO,'|');
  14.  
  15.   writeln('S2PARSE = ',S2PARSE);
  16.   writeln('SEEALSO = ',sSEEALSO);
  17. end.
  18.  
is result:
Code: [Select]
S2PARSE = function FutureValue(ARate: Float; NPeriods: Integer; APayment: Float; APresentValue: Float; APaymentTime: TPaymentTime ): Float; Description FutureValue calculates the future value of an investment (FV) in the cash flow formula. 
SEEALSO = See also InterestRate Calculate the interest rate value of an investment NumberOfPeriods Calculate the number of periods for an investment Payment Calculate the payment for an investment PresentValue Calculate the present value given the future value of an investment.
« Last Edit: August 29, 2022, 11:58:16 pm by Thausand »

 

TinyPortal © 2005-2018