Duvidas com o Tmemo no delphi
16/12/2021
0
vertical, queira saber se tem como gerar eles na horizontal ou se o proprio memo tem essa opçao.
procedure TForm1.btn_geradorClick(Sender: TObject);
var auxiliar, qtdnumeros, qtdglobal: integer;
begin
//pre-requisito do funcionamento do sistema, onde e verificado os valores dos edits
if txt_faixa.Text = '''' then
begin
ShowMessage(''Digite um numero valido'');
txt_faixa.SetFocus;
Exit;
end;
Memo1.Clear;
qtdglobal := 0;
if txt_gerar_ate.Text = '''' then
txt_gerar_ate.Text := txt_faixa.Text;
if StrToInt(txt_gerar_ate.Text) > StrToInt(txt_faixa.Text) then
txt_gerar_ate.Text := txt_faixa.Text;
ProgressBar1.Max := StrToInt(txt_gerar_ate.Text);
if (StrToInt(txt_gerar_ate.Text) < StrToInt(txt_faixa.Text)) then
begin
while ((Memo1.Lines.Count < (StrToInt(txt_gerar_ate.Text)))) do
begin
qtdglobal := qtdglobal+1;
qtdnumeros := (StrToInt(txt_faixa.Text));
auxiliar := Random(qtdnumeros);
auxiliar := auxiliar+1;
if not ((Memo1.Lines.IndexOf(IntToStr(auxiliar)) > -1) and (memo1.Lines.IndexOf(IntToStr(auxiliar)) < qtdnumeros)) then
Memo1.Lines.Add(IntToStr(auxiliar));
ProgressBar1.Position := Memo1.Lines.Count;
end;
end
else
begin
while ((Memo1.Lines.Count < (StrToInt(txt_faixa.Text)))) do
begin
qtdglobal := qtdglobal+1;
qtdnumeros := (StrToInt(txt_faixa.Text));
auxiliar := Random(qtdnumeros);
auxiliar := auxiliar+1;
if not ((Memo1.Lines.IndexOf(IntToStr(auxiliar)) > -1) and (Memo1.Lines.IndexOf(IntToStr(auxiliar)) < qtdnumeros)) then
Memo1.Lines.Add(IntToStr(auxiliar));
ProgressBar1.Position := Memo1.Lines.Count;
end;
end;
//parte final, depois que e gerado os numeros
txt_gerados.Text := IntToStr(Memo1.Lines.Count);
txt_repeticoes.Text := (IntToStr(qtdglobal));
if txt_gerar_ate.Text = '''' then
txt_gerar_ate.Text := txt_faixa.Text;
if (Memo1.Lines.Count = StrToInt(txt_gerar_ate.Text)) then
ShowMessage(''Lista gerada com sucesso!'');
end;
Anderson Saldanha
Post mais votado
22/12/2021
// memoaux.parent := Form1; // P2 21/12/2021
// Você estava realizando o FreeAndNil, e logo em seguida tentava usa-lo novamente.
// Apresentou erro também, movi para o final do código e debuguei, deu certo
//memoaux.parent := Nomedoseuform
procedure TForm1.btn_geradorClick(Sender: TObject);
var
auxiliar, qtdglobal: integer;
faixa, gerar_ate, limite: integer;
txtauxiliar, txtaux: string;
memoaux: TMemo;
begin
//pre-requisito do funcionamento do sistema, onde e verificado os valores dos edits
if txt_faixa.Text = '' then
begin
ShowMessage('Digite um numero valido');
txt_faixa.SetFocus;
Exit;
end;
qtdglobal := 0;
txtaux := '';
if txt_gerar_ate.Text = '' then
txt_gerar_ate.Text := txt_faixa.Text;
if StrToInt(txt_gerar_ate.Text) > StrToInt(txt_faixa.Text) then
txt_gerar_ate.Text := txt_faixa.Text;
// faixa := StrToIntDef(txt_faixa.Text,1),
faixa := StrToIntDef(txt_faixa.Text,1);
gerar_ate := StrToIntDef(txt_gerar_ate.Text,faixa);
ProgressBar1.Max := gerar_ate;
if (gerar_ate < faixa) then
limite := gerar_ate
else
limite := faixa;
memoaux := TMemo.Create(nil);
memoaux.parent := Form1; // P2 21/12/2021
while (memoaux.Lines.Count < limite) do
begin
Inc(qtdglobal);
auxiliar := Random(faixa) + 1;
// txtauxiliar := IntToStr(auxiliar)
txtauxiliar := IntToStr(auxiliar);
if not ((memoaux.Lines.IndexOf(txtauxiliar) > -1) and (memoaux.Lines.IndexOf(txtauxiliar) < faixa)) then
begin
memoaux.Lines.Add(txtauxiliar);
// txtaux := txtaux + ', ' + txtauxiliar;
txtaux := txtaux + ' ' + txtauxiliar;
end;
ProgressBar1.Position := memoaux.Lines.Count;
end;
//P2 22/12/2021
//FreeAndNil(memoaux); // Se ainda pretende, não pode libera-lo ainda
//parte final, depois que sao gerados os numeros
txt_gerados.Text := IntToStr(memoaux.Lines.Count); // Já foi liberado da memória, daria erro
txt_repeticoes.Text := IntToStr(qtdglobal);
Memo1.Clear;
Memo1.Lines.Add( txtaux );
if (memoaux.Lines.Count = gerar_ate) then
ShowMessage('Lista gerada com sucesso!');
//P2 22/12/2021
FreeAndNil(memoaux); // Liberar somente no final
end;
Raimundo Pereira
Mais Posts
17/12/2021
Emerson Nascimento
procedure TForm1.btn_geradorClick(Sender: TObject); var auxiliar, qtdglobal: integer; faixa, gerar_ate, limite: integer; txtauxiliar, txtaux: string; memoaux: TMemo; begin //pre-requisito do funcionamento do sistema, onde e verificado os valores dos edits if txt_faixa.Text = '' then begin ShowMessage('Digite um numero valido'); txt_faixa.SetFocus; Exit; end; qtdglobal := 0; txtaux := ''; if txt_gerar_ate.Text = '' then txt_gerar_ate.Text := txt_faixa.Text; if StrToInt(txt_gerar_ate.Text) > StrToInt(txt_faixa.Text) then txt_gerar_ate.Text := txt_faixa.Text; faixa := StrToIntDef(txt_faixa.Text,1), gerar_ate := StrToIntDef(txt_gerar_ate.Text,faixa); ProgressBar1.Max := gerar_ate; if (gerar_ate < faixa) then limite := gerar_ate else limite := faixa; memoaux := TMemo.Create(nil); while (memoaux.Lines.Count < limite) do begin Inc(qtdglobal); auxiliar := Random(faixa) + 1; txtauxiliar := IntToStr(auxiliar) if not ((memoaux.Lines.IndexOf(txtauxiliar) > -1) and (memoaux.Lines.IndexOf(txtauxiliar) < faixa)) then begin memoaux.Lines.Add(txtauxiliar); // txtaux := txtaux + ', ' + txtauxiliar; txtaux := txtaux + ' ' + txtauxiliar; end; ProgressBar1.Position := memoaux.Lines.Count; end; FreeAndNil(memoaux); //parte final, depois que sao gerados os numeros txt_gerados.Text := IntToStr(memoaux.Lines.Count); txt_repeticoes.Text := IntToStr(qtdglobal); Memo1.Clear; Memo1.Lines.Add( txtaux ); if (memoaux.Lines.Count = gerar_ate) then ShowMessage('Lista gerada com sucesso!'); end;
20/12/2021
Anderson Saldanha
First chance exception at $7511B522. Exception class EInvalidOperation with message 'Control '' has no parent window'. Process F_Sorteio.exe (10784)
21/12/2021
Raimundo Pereira
First chance exception at $7511B522. Exception class EInvalidOperation with message 'Control '' has no parent window'. Process F_Sorteio.exe (10784)
procedure TForm1.btn_geradorClick(Sender: TObject); var auxiliar, qtdglobal: integer; faixa, gerar_ate, limite: integer; txtauxiliar, txtaux: string; memoaux: TMemo; begin //pre-requisito do funcionamento do sistema, onde e verificado os valores dos edits if txt_faixa.Text = '' then begin ShowMessage('Digite um numero valido'); txt_faixa.SetFocus; Exit; end; qtdglobal := 0; txtaux := ''; if txt_gerar_ate.Text = '' then txt_gerar_ate.Text := txt_faixa.Text; if StrToInt(txt_gerar_ate.Text) > StrToInt(txt_faixa.Text) then txt_gerar_ate.Text := txt_faixa.Text; faixa := StrToIntDef(txt_faixa.Text,1), gerar_ate := StrToIntDef(txt_gerar_ate.Text,faixa); ProgressBar1.Max := gerar_ate; if (gerar_ate < faixa) then limite := gerar_ate else limite := faixa; memoaux := TMemo.Create(nil); memoaux.parent := Form1; // P2 21/12/2021 while (memoaux.Lines.Count < limite) do begin Inc(qtdglobal); auxiliar := Random(faixa) + 1; txtauxiliar := IntToStr(auxiliar) if not ((memoaux.Lines.IndexOf(txtauxiliar) > -1) and (memoaux.Lines.IndexOf(txtauxiliar) < faixa)) then begin memoaux.Lines.Add(txtauxiliar); // txtaux := txtaux + ', ' + txtauxiliar; txtaux := txtaux + ' ' + txtauxiliar; end; ProgressBar1.Position := memoaux.Lines.Count; end; FreeAndNil(memoaux); //parte final, depois que sao gerados os numeros txt_gerados.Text := IntToStr(memoaux.Lines.Count); txt_repeticoes.Text := IntToStr(qtdglobal); Memo1.Clear; Memo1.Lines.Add( txtaux ); if (memoaux.Lines.Count = gerar_ate) then ShowMessage('Lista gerada com sucesso!'); end;
21/12/2021
Anderson Saldanha
First chance exception at $7511B522. Exception class EInvalidOperation with message 'Control '' has no parent window'. Process F_Sorteio.exe (10784)
procedure TForm1.btn_geradorClick(Sender: TObject); var auxiliar, qtdglobal: integer; faixa, gerar_ate, limite: integer; txtauxiliar, txtaux: string; memoaux: TMemo; begin //pre-requisito do funcionamento do sistema, onde e verificado os valores dos edits if txt_faixa.Text = '' then begin ShowMessage('Digite um numero valido'); txt_faixa.SetFocus; Exit; end; qtdglobal := 0; txtaux := ''; if txt_gerar_ate.Text = '' then txt_gerar_ate.Text := txt_faixa.Text; if StrToInt(txt_gerar_ate.Text) > StrToInt(txt_faixa.Text) then txt_gerar_ate.Text := txt_faixa.Text; faixa := StrToIntDef(txt_faixa.Text,1), gerar_ate := StrToIntDef(txt_gerar_ate.Text,faixa); ProgressBar1.Max := gerar_ate; if (gerar_ate < faixa) then limite := gerar_ate else limite := faixa; memoaux := TMemo.Create(nil); memoaux.parent := Form1; // P2 21/12/2021 while (memoaux.Lines.Count < limite) do begin Inc(qtdglobal); auxiliar := Random(faixa) + 1; txtauxiliar := IntToStr(auxiliar) if not ((memoaux.Lines.IndexOf(txtauxiliar) > -1) and (memoaux.Lines.IndexOf(txtauxiliar) < faixa)) then begin memoaux.Lines.Add(txtauxiliar); // txtaux := txtaux + ', ' + txtauxiliar; txtaux := txtaux + ' ' + txtauxiliar; end; ProgressBar1.Position := memoaux.Lines.Count; end; FreeAndNil(memoaux); //parte final, depois que sao gerados os numeros txt_gerados.Text := IntToStr(memoaux.Lines.Count); txt_repeticoes.Text := IntToStr(qtdglobal); Memo1.Clear; Memo1.Lines.Add( txtaux ); if (memoaux.Lines.Count = gerar_ate) then ShowMessage('Lista gerada com sucesso!'); end;
21/12/2021
Anderson Saldanha
First chance exception at $7511B522. Exception class EInvalidOperation with message 'Control '' has no parent window'. Process F_Sorteio.exe (10784)
procedure TForm1.btn_geradorClick(Sender: TObject); var auxiliar, qtdglobal: integer; faixa, gerar_ate, limite: integer; txtauxiliar, txtaux: string; memoaux: TMemo; begin //pre-requisito do funcionamento do sistema, onde e verificado os valores dos edits if txt_faixa.Text = '' then begin ShowMessage('Digite um numero valido'); txt_faixa.SetFocus; Exit; end; qtdglobal := 0; txtaux := ''; if txt_gerar_ate.Text = '' then txt_gerar_ate.Text := txt_faixa.Text; if StrToInt(txt_gerar_ate.Text) > StrToInt(txt_faixa.Text) then txt_gerar_ate.Text := txt_faixa.Text; faixa := StrToIntDef(txt_faixa.Text,1), gerar_ate := StrToIntDef(txt_gerar_ate.Text,faixa); ProgressBar1.Max := gerar_ate; if (gerar_ate < faixa) then limite := gerar_ate else limite := faixa; memoaux := TMemo.Create(nil); memoaux.parent := Form1; // P2 21/12/2021 while (memoaux.Lines.Count < limite) do begin Inc(qtdglobal); auxiliar := Random(faixa) + 1; txtauxiliar := IntToStr(auxiliar) if not ((memoaux.Lines.IndexOf(txtauxiliar) > -1) and (memoaux.Lines.IndexOf(txtauxiliar) < faixa)) then begin memoaux.Lines.Add(txtauxiliar); // txtaux := txtaux + ', ' + txtauxiliar; txtaux := txtaux + ' ' + txtauxiliar; end; ProgressBar1.Position := memoaux.Lines.Count; end; FreeAndNil(memoaux); //parte final, depois que sao gerados os numeros txt_gerados.Text := IntToStr(memoaux.Lines.Count); txt_repeticoes.Text := IntToStr(qtdglobal); Memo1.Clear; Memo1.Lines.Add( txtaux ); if (memoaux.Lines.Count = gerar_ate) then ShowMessage('Lista gerada com sucesso!'); end;
Deu Acess Violation adiconando 'memoaux.Parent := Form1; '
22/12/2021
Anderson Saldanha
// memoaux.parent := Form1; // P2 21/12/2021
// Você estava realizando o FreeAndNil, e logo em seguida tentava usa-lo novamente.
// Apresentou erro também, movi para o final do código e debuguei, deu certo
//memoaux.parent := Nomedoseuform
procedure TForm1.btn_geradorClick(Sender: TObject);
var
auxiliar, qtdglobal: integer;
faixa, gerar_ate, limite: integer;
txtauxiliar, txtaux: string;
memoaux: TMemo;
begin
//pre-requisito do funcionamento do sistema, onde e verificado os valores dos edits
if txt_faixa.Text = '' then
begin
ShowMessage('Digite um numero valido');
txt_faixa.SetFocus;
Exit;
end;
qtdglobal := 0;
txtaux := '';
if txt_gerar_ate.Text = '' then
txt_gerar_ate.Text := txt_faixa.Text;
if StrToInt(txt_gerar_ate.Text) > StrToInt(txt_faixa.Text) then
txt_gerar_ate.Text := txt_faixa.Text;
// faixa := StrToIntDef(txt_faixa.Text,1),
faixa := StrToIntDef(txt_faixa.Text,1);
gerar_ate := StrToIntDef(txt_gerar_ate.Text,faixa);
ProgressBar1.Max := gerar_ate;
if (gerar_ate < faixa) then
limite := gerar_ate
else
limite := faixa;
memoaux := TMemo.Create(nil);
memoaux.parent := Form1; // P2 21/12/2021
while (memoaux.Lines.Count < limite) do
begin
Inc(qtdglobal);
auxiliar := Random(faixa) + 1;
// txtauxiliar := IntToStr(auxiliar)
txtauxiliar := IntToStr(auxiliar);
if not ((memoaux.Lines.IndexOf(txtauxiliar) > -1) and (memoaux.Lines.IndexOf(txtauxiliar) < faixa)) then
begin
memoaux.Lines.Add(txtauxiliar);
// txtaux := txtaux + ', ' + txtauxiliar;
txtaux := txtaux + ' ' + txtauxiliar;
end;
ProgressBar1.Position := memoaux.Lines.Count;
end;
//P2 22/12/2021
//FreeAndNil(memoaux); // Se ainda pretende, não pode libera-lo ainda
//parte final, depois que sao gerados os numeros
txt_gerados.Text := IntToStr(memoaux.Lines.Count); // Já foi liberado da memória, daria erro
txt_repeticoes.Text := IntToStr(qtdglobal);
Memo1.Clear;
Memo1.Lines.Add( txtaux );
if (memoaux.Lines.Count = gerar_ate) then
ShowMessage('Lista gerada com sucesso!');
//P2 22/12/2021
FreeAndNil(memoaux); // Liberar somente no final
end;
Era isso mesmo obrigado P2 , meu form e Form1 mesmo kkk
Clique aqui para fazer login e interagir na Comunidade :)