Y
Y
Yam0lod5y2020-08-01 05:57:20
JavaScript
Yam0lod5y, 2020-08-01 05:57:20

Javascript in Delphi?

I'm trying to rewrite js code in delphi

function columnToLetter(column){
  var temp, letter = ''; 
  while (column > 0) {
   temp = (column - 1) % 26;
   letter = String.fromCharCode(temp + 65) + letter;
   column = (column - temp - 1) / 26;
  }
  console.log(letter)
  return letter;
 }

My code is still in progress, but I still don't understand something
function TFormMenu.FromCharCode(ch: array of byte): AnsiString;
var
  L: Integer;
begin
  L := Length(ch);
  SetLength(result, L);
  if L > 0 then
    Move(ch[0], result[1], L);
end;

function TFormMenu.columnToLetter(column: Integer): string;
var
  temp: integer;
  letter : string;
  ch: array[0..500] of byte;
begin
  while (column > 0) do
  begin
    temp := (column - 1) mod 26;
    ch[s] := ((temp + 65) + StrToInt(letter));
  if inttostr(ch[s]) <> '0' then
      letter := letter + FromCharCode(ch[s]);
    end;
    letter := result;
    column := round((column - temp - 1) / 26);
  end;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hemul GM, 2020-08-01
@Yam0lod5y

function columnToLetter(column: Integer): string;
var
  temp: Integer;
begin
  Result := '';
  while (column > 0) do
  begin
    temp := (column - 1) mod 26;
    Result := Char(temp + 65) + Result;
    column := (column - temp - 1) div 26;
  end;
end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question