Duvida pra uma função com resultado em byte
Olá a todos!
pow, sabe aquele problema que é fácil, tá na tua cara, vc pensa, pensa, pensa, e torra de tando pensar, mas não consegue enxergar de jeito nenhum? (hehe, pelo menos pra mim, que tou iniciando...) :?
rs, então.... aí vai o problema...
Eu simplifiquei algumas coisas pra ficar mais claro de entender aqui...
Bom, primeiro eu precisava de algumas strings pra colocar num ComboBox aí fiz:
(é meio complicado de explicar pq eu não coloquei logo nos itens do ComboBox, mas o negócio é que eu precisava assim mesmo)
[b:20d58de2f2]var[/b:20d58de2f2]
number: [b:20d58de2f2]array[/b:20d58de2f2] [0..200] [b:20d58de2f2]of string[/b:20d58de2f2];
number[0]:= ´zero´;
number[1]:= ´um´;
number[2]:= ´dois´;
number[3]:= ´três´;
etc....
depois eu precisava de uma função(com resultado em [b:20d58de2f2][color=red:20d58de2f2]byte[/color:20d58de2f2][/b:20d58de2f2]) que dependendo do item escolhido no ComboBox ela me retorna-se o valor da string que ela estava... (putz... compliquei tudo)
ex:
se no programa a ComboBox estivesse no ´TRÊS´, a função teria que me retornar o valor 3 em byte
Me pareceu tão simples quando eu tava planejando, mas depois, tudo que consegui foi ficar com dor de cabeça pensando na função...
:?: Alguém aí pode me ajudar??? :?:
valeu todo mundo
e obrigado ao LordGlacius que me ajudou mto resolvendo aquele problema dos atributos!
VALEU! Té+
pow, sabe aquele problema que é fácil, tá na tua cara, vc pensa, pensa, pensa, e torra de tando pensar, mas não consegue enxergar de jeito nenhum? (hehe, pelo menos pra mim, que tou iniciando...) :?
rs, então.... aí vai o problema...
Eu simplifiquei algumas coisas pra ficar mais claro de entender aqui...
Bom, primeiro eu precisava de algumas strings pra colocar num ComboBox aí fiz:
(é meio complicado de explicar pq eu não coloquei logo nos itens do ComboBox, mas o negócio é que eu precisava assim mesmo)
[b:20d58de2f2]var[/b:20d58de2f2]
number: [b:20d58de2f2]array[/b:20d58de2f2] [0..200] [b:20d58de2f2]of string[/b:20d58de2f2];
number[0]:= ´zero´;
number[1]:= ´um´;
number[2]:= ´dois´;
number[3]:= ´três´;
etc....
depois eu precisava de uma função(com resultado em [b:20d58de2f2][color=red:20d58de2f2]byte[/color:20d58de2f2][/b:20d58de2f2]) que dependendo do item escolhido no ComboBox ela me retorna-se o valor da string que ela estava... (putz... compliquei tudo)
ex:
se no programa a ComboBox estivesse no ´TRÊS´, a função teria que me retornar o valor 3 em byte
Me pareceu tão simples quando eu tava planejando, mas depois, tudo que consegui foi ficar com dor de cabeça pensando na função...
:?: Alguém aí pode me ajudar??? :?:
valeu todo mundo
e obrigado ao LordGlacius que me ajudou mto resolvendo aquele problema dos atributos!
VALEU! Té+
Neville
Curtidas 0
Respostas
Motta
28/11/2003
TStringList, tem os metodos AdObjects e Objects vc pode
ao adicionar um item passar o valor que vc quer
sl.AddObjects(´um´,Pointer(1);
sl.AddObjects(´2´,Pointer(2);
para recuperar
Integer(sl.Objects[0])
veja um exemplo do Delphi
----
This example requires a TListView, a TImageList and a TComboBox. You will need to double click the image list and add several images to the image list prior to running the project. You can use *.bmp or *.ico files from the \Images\Icons directory.
During the form’s OnCreate event handler, items for the List View control are created for each image in the Image List and the ImageIndex is assigned the number of the image within the ImageList. Two columns are created so that when ViewStyle is vsReport, you will have columns to view.
Also within the form’s OnCreate event handler assign the ComboBox each of the four TViewStyle constants to the Items’ Objects property. You could also simply code this within a series of OnClick event handlers as, for instance, ListView1.ViewStyle := vsIcon.
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
ListItem: TListItem;
NewColumn: TListColumn;
begin
// Create a ListView item for each image in the ImageList
with ListView1 do
begin
SmallImages := ImageList1;
LargeImages := ImageList1;
for I := 0 to ImageList1.Count - 1 do
begin
ListItem := Items.Add;
Listitem.Caption := ´Image´ + IntToStr(I);
ListItem.ImageIndex := I;
end;
// Create two columns to show during viewing as vsReport
NewColumn := Columns.Add;
NewColumn.Caption := ´Column 1´;
NewColumn := Columns.Add;
NewColumn.Caption := ´Column 2´;
// Add View styles and constants to the Combo Box
ComboBox1.Items.AddObject(´vsIcon´, TObject(vsIcon));
ComboBox1.Items.AddObject(´vsList´, TObject(vsList));
ComboBox1.Items.AddObject(´vsReport´, TObject(vsReport));
ComboBox1.Items.AddObject(´vsSmallIcon´, TObject(vsSmallIcon));
// Display first item in the Combo Box
ComboBox1.ItemIndex := 0;
end;
end;
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
with ComboBox1 do
ListView1.ViewStyle := TViewStyle(Items.Objects[ItemIndex]);
end;
----
ao adicionar um item passar o valor que vc quer
sl.AddObjects(´um´,Pointer(1);
sl.AddObjects(´2´,Pointer(2);
para recuperar
Integer(sl.Objects[0])
veja um exemplo do Delphi
----
This example requires a TListView, a TImageList and a TComboBox. You will need to double click the image list and add several images to the image list prior to running the project. You can use *.bmp or *.ico files from the \Images\Icons directory.
During the form’s OnCreate event handler, items for the List View control are created for each image in the Image List and the ImageIndex is assigned the number of the image within the ImageList. Two columns are created so that when ViewStyle is vsReport, you will have columns to view.
Also within the form’s OnCreate event handler assign the ComboBox each of the four TViewStyle constants to the Items’ Objects property. You could also simply code this within a series of OnClick event handlers as, for instance, ListView1.ViewStyle := vsIcon.
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
ListItem: TListItem;
NewColumn: TListColumn;
begin
// Create a ListView item for each image in the ImageList
with ListView1 do
begin
SmallImages := ImageList1;
LargeImages := ImageList1;
for I := 0 to ImageList1.Count - 1 do
begin
ListItem := Items.Add;
Listitem.Caption := ´Image´ + IntToStr(I);
ListItem.ImageIndex := I;
end;
// Create two columns to show during viewing as vsReport
NewColumn := Columns.Add;
NewColumn.Caption := ´Column 1´;
NewColumn := Columns.Add;
NewColumn.Caption := ´Column 2´;
// Add View styles and constants to the Combo Box
ComboBox1.Items.AddObject(´vsIcon´, TObject(vsIcon));
ComboBox1.Items.AddObject(´vsList´, TObject(vsList));
ComboBox1.Items.AddObject(´vsReport´, TObject(vsReport));
ComboBox1.Items.AddObject(´vsSmallIcon´, TObject(vsSmallIcon));
// Display first item in the Combo Box
ComboBox1.ItemIndex := 0;
end;
end;
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
with ComboBox1 do
ListView1.ViewStyle := TViewStyle(Items.Objects[ItemIndex]);
end;
----
GOSTEI 0
Marcelo Saviski
28/11/2003
da p/ tentar fazer uma busca pelo nome assim:
var I: Integer; begin for I := 0 to 200 do if upperCase(ComboBox.itens[ComboBox.ItenIndex]) = Uppercase(number[I]) then begin ShowMessage(intToStr(number[I])); Break; end; end;
GOSTEI 0