Destruktion
Programmer
Hi, I am trying to convert a small fun project from VB (I did not write the VB code, found it at this site:
Anyway this is what i got so far, it compiles and runs but I dont get the same output.
Original VB Code:
My Delphi Code:
I tried running my source with the exact same text as used in the link at the top: testing 123 testing, my output is different though.
Appreciate some help thanks.
Anyway this is what i got so far, it compiles and runs but I dont get the same output.
Original VB Code:
Code:
Dim selColor As Long
Private Sub cmbColors_Click()
selColor = CLng("&h" & cmbColors.Text)
picColor.BackColor = selColor
End Sub
Private Sub cmdClear_Click()
txtText.Text = ""
txtBBCode.Text = ""
End Sub
Private Sub cmdConvert_Click()
Dim x As Integer, sConverted As String, sLetter As String, cColor As Long
Dim Rev As Boolean
cColor = selColor
For x = 1 To Len(txtText.Text)
sLetter = Mid(txtText.Text, x, 1)
If Not sLetter = " " Then
sConverted = sConverted & "[color=#" & Right("000000" & Hex(cColor), 6) & "]" & sLetter & "[/color]"
If cColor = selColor + &HFF Then
Rev = True
End If
If cColor = selColor Then
Rev = False
End If
If Rev Then
cColor = cColor - &H33
Else
cColor = cColor + &H33
End If
Else
sConverted = sConverted & " "
End If
Next
If chkBold.Value Then
txtBBCode.Text = "[b]" & sConverted & "[/b]"
Else
txtBBCode.Text = sConverted
End If
cmdCopy_Click
End Sub
Private Sub cmdCopy_Click()
Clipboard.Clear
Clipboard.SetText txtBBCode.Text
End Sub
Private Sub Form_Load()
cmbColors.ListIndex = 0
End Sub
My Delphi Code:
Code:
private
function TextToGradientBBCode(sInput: String): String;
var
SelColor: LongInt;
function Mid(Source: string; Start: integer; Length: integer): string;
begin
Result := copy(Source,Start,Length);
end;
function Left(Source: string; Length: integer): string;
begin
Result := copy(Source,1,Length);
end;
function Right(Source: string; Lengths: integer): string;
begin
Result := copy(source,Length(Source) - Lengths,Lengths);
end;
function TForm1.TextToGradientBBCode(sInput: String): String;
var
X: Integer;
sConverted: String;
sLetter: String;
cColor: LongInt;
Rev: Boolean;
begin
Result:= '';
cColor:= SelColor;
for X:= 1 to Length(sInput) do
begin
sLetter:= Mid(sInput, X, 1);
if sLetter <> ' ' then
begin
sConverted:= sConverted + '[color=#' + Right('000000' + IntToStr(cColor), 6) + ']' + sLetter + '[/color]';
if cColor = SelColor + $FF then //TColor($FF) then
Rev:= True;
if cColor = SelColor then
Rev:= False;
if Rev then
cColor:= cColor - $33 //TColor($33)
else
cColor:= cColor + $33 //TColor($33)
end
else
sConverted:= sConverted + ' ';
end;
Result:= sConverted;
end;
procedure TForm1.cmdConvertClick(Sender: TObject);
begin
SelColor:= clBlack; //TColor($000000);
txtOutput.Lines.Text:= TextToGradientBBCode(txtInput.Lines.Text);
end;
I tried running my source with the exact same text as used in the link at the top: testing 123 testing, my output is different though.
Appreciate some help thanks.