Ok i wrote this function to print as many characters as needed but it doesnt work can anyone help me? It only fails in loops where after every cycle the number of times gets multiplied.

Function TfrmDeliveries.WriteChar (letter : char; times : Integer): String;
var
i_count : Integer;
s_temp : string;
begin
  s_temp := '';

   for i_count := 0 to times - 1 do
   begin
     s_temp := s_temp + letter ;   //Function used to write a char many times
   end;                            //it takes in 2 parameters it adds the letter

   result := s_temp;                                //to the string as many times as needed
end;

Recommended Answers

All 2 Replies

Listen this little pascal program :D

program write_chars;

var main_st:string;


function characters(letter:char; times:integer):string;
var i_count:integer;
    s_temp:string;
begin
  s_temp:='';
  for i_count:=0 to times do begin
      s_temp:=s_temp+letter;
  end;
  characters:=s_temp; (*right reference!!*)
end;(*characters*)

begin

  writeln(characters('@',10)); (*call it within writeln*)

  main_st:=characters('$',4);   (*main_st's value is: $$$$*)

end.
(*created by FlamingClaw.2010.04.15.Hungary.*)

I don't see any error in your code, but try change something:
- assign the times' value to a local variable
- replace that 'for' with a 'while'
- instead of this function, use Delphi's build-in function DupeString( from StrUtils) - it has the same signature as yours.

Cheers,
Ionut

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.