Recent

Author Topic: [EXAMPLE TlistBox.Filtered]  (Read 285 times)

What I can do

  • Full Member
  • ***
  • Posts: 115
[EXAMPLE TlistBox.Filtered]
« on: October 31, 2024, 05:55:10 pm »
OS:Windows 10
Lazarus 3.4
Project: a List box mixed with the path of a file names that extensions are bmp, gif, ani, ico
I would like to click on radio, check box, or edit combo type input to pick the filter extensions.
I thought ListBox1.Filter('.bmp') would maybe get me close but I have not yet found how to use it.
could anyone point me into a help source article or link
« Last Edit: October 31, 2024, 08:10:32 pm by What I can do »

TRon

  • Hero Member
  • *****
  • Posts: 3463
Re: TlistBox.TStringsFilterMethod How do I use this
« Reply #1 on: October 31, 2024, 07:17:48 pm »
Not really help or an article but a small example (hopefully you are able to read/understand code)
This tagline is powered by AI

What I can do

  • Full Member
  • ***
  • Posts: 115
Re: TlistBox.TStringsFilterMethod How do I use this
« Reply #2 on: October 31, 2024, 08:09:45 pm »
Thank you! WOW!

Not only was this perfect but pointed me towards a much better understanding, with other question
followed by WTF moments such as
------------------------------------------------------
writestr(naming, 'file-', n, extensions[index]);
//...
for naming in extensions
  do

for SelectedExtension in SelectedExtensions
  do
//...
then exit(true);

 
again thank you for taking the time from your scedual.

What I can do

  • Full Member
  • ***
  • Posts: 115
Re: [EXAMPLE TlistBox.Filtered]
« Reply #3 on: October 31, 2024, 09:39:53 pm »
interesting...
at cursor writestr|
[Alt][up arrow]  Nothing?
[Ctrl][Space] pop up window shows WriteStr(var S:String;Args:Arguments);
ok, I don't know which unit it is from.
so if Arguments is a variable type
can it be used to see all its parameters.
but no,  a:Arguments is an error?

So now...
https://wiki.lazarus.freepascal.org/WriteStr

is good reading but...
Had to follow up with this
https://wiki.lazarus.freepascal.org/Write

awsome this is what I like about examples. Many times they open doors to other doors. :)

TRon

  • Hero Member
  • *****
  • Posts: 3463
Re: [EXAMPLE TlistBox.Filtered]
« Reply #4 on: October 31, 2024, 11:04:30 pm »
Your welcome "What I can do" and I'm glad to see that you were able to solve your issue.

Quote
followed by WTF moments
It is another way of iterating an array that doesn't require to declare a separate index iterator.

In practice you can do that for any array (enumerable type), e.g:
Code: Pascal  [Select][+][-]
  1. type
  2.   TFoo = record
  3.    Bar : string;
  4.   end;
  5.   TFooArray : array of TFoo;
  6. var
  7.   Foo      : TFoo;
  8.   FooArray : TFooArray; // array is empty, needs to be "filled" before the routine below actually outputs something
  9. begin
  10.   for Foo in FooArray
  11.     do writeln(Foo.Bar)
  12. end;
  13.  
Do note that in this case the iterator is a copy of the record and not the record itself. That means that changing any of the fields of the iterator is not actually 'stored' in the array.

See also for..do documentation

Quote
The enumerable expression can be one of five cases:
- An enumeration type identifier. The loop will then be over all elements of the enumeration type. The control variable must be of the enumeration type.
- A set value. The loop will then be over all elements in the set, the control variable must be of the base type of the set.
- An array value. The loop will be over all elements in the array, and the control variable must have the same type as an element in the array. As a special case, a string is regarded as an array of characters.
- An enumerable class, object, or extended record instance. This is an instance of any structured type that supports the IEnumerator and IEnumerable interfaces. In this case, the control variable’s type must equal the type of the IEnumerator.GetCurrent return value.
- Any type for which an enumerator operator is defined. The enumerator operator must return a structured type that implements the IEnumerator interface. The type of the control variable’s type must equal the type of the enumerator’s GetCurrent return value type.

Quote
interesting...at cursor writestr
WriteStr works, as the documentation mentions, similar as write (or writeln but withouth the newline character added).

Meaning that whatever type that can be written by write works exactly the same as when using WriteStr.

The (only) difference is that the first parameter of WriteStr is the string that everything is written to (instead of writing the generated text to the standard output handle).

If wanted it is possible to use writestr to 'extend' the string like:
Code: Text  [Select][+][-]
  1. var
  2.   s : string;
  3. begin
  4.   writestr(s, '');
  5.   writestr(s, s, 'Foo');  // s contains "Foo"
  6.   writestr(s, s, 'bar');  // s contains "Foobar"
  7. end;
  8.  

If there are any (other) questions then feel free to ask.

Perhaps the above ramblings might be useful to someone.
« Last Edit: October 31, 2024, 11:06:07 pm by TRon »
This tagline is powered by AI

 

TinyPortal © 2005-2018