Watch, Follow, &
Connect with Us

Embarcadero Blogs

Latest Posts


Using regular expressions to validate IP address with Delphi XE

One of the new Delphi XE features is RTL support for regular expressions  (unit RegularExpressions), regular expressions provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters.

The follow example shows how to use regexp to validate IP address.

program RegExpIP;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  RegularExpressions;

var
 ipRegExp : String;
begin
  try

    ipRegExp := '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b';

  if TRegEx.IsMatch(paramstr(1), ipRegExp) then
    Writeln('Text DOES match the regular expression')
  else
    Writeln('Text DOES NOT match the regular expression');

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Just execute the program and pass the IP address as parameter.

In this case the IP address is valid
RegExpIP 200.100.2.21
Text DOES match the regular expression

In this case not, the IP address finish with 243, it is out of the range which is 255
RegExpIP 200.100.2.243
Text DOES match the regular expression

On the RAD Studio demo repository at sourceforge you can find a project sample showing other regular expressions that you can use.

As well download the Delphi XE trial and start looking the other great features on this release,  download the trial here

Related Posts


posted @ Wed, 08 Sep 2010 23:57:30 +0000 by Andreano Lanusse


Utilizando expressões regulares para validar endereço IP no Delphi XE

Umas das novidades no Delphi XE e o suporte a expressões regulares (unit RegularExpressions) na RTL, esse recursos nos permite fazer diversos tipos de validação, abaixo um exemplo de como utilizar este recurso para validar se o valor em uma string é realmente um endereço IP.

program RegExpIP;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  RegularExpressions;

var
 ipRegExp : String;
begin
  try

    ipRegExp := '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b';

  if TRegEx.IsMatch(paramstr(1), ipRegExp) then
    Writeln('Text DOES match the regular expression')
  else
    Writeln('Text DOES NOT match the regular expression');

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Para validar basta executar o programa e passar como parâmetro o endereço IP

Neste caso o IP é válido
RegExpIP 200.100.2.21
Text DOES match the regular expression

Neste caso o IP não é valido, pois 243 está fora do intervalo permitido
RegExpIP 200.100.2.243
Text DOES match the regular expression

No repositório de exemplos do RAD Studio você pode encontrar um exemplo com outros tipos de expressões regulares.

Faça o download da versão trial do Delphi XE aqui

Posts relacionados


posted @ Wed, 08 Sep 2010 23:46:26 +0000 by Andreano Lanusse


RAD Studio XE Editor Enhancements

There are a couple other little editor enhancements in RAD Studio XE that I wanted to highlight:

Templates In Code Completion

Code Templates have appeared in the code completion list for several releases. However, the code completion list has just shown the name of the code template. Often, the template name is not descriptive enough to know what the code template will do. In RAD Studio XE, the description of the code template will now also appear in the completion list:

Code Template Completion

Code Template Completion

Code Templates are one of the most powerful features of the RAD Studio code editor. This little enhancement should help to make them even easier to use.

Brace Highlighting

Brace Highlighting

Brace Highlighting

Brace Highlighting is another great editor feature that has been in RAD Studio for several releases. Personally, I find it invaluable for writing and debugging complex expressions. But, it is not popular with everyone. In RAD Studio XE, there is now a checkbox in the Editor Options (Tools/Options/Editor Options) for "Highlight brace pairs". It is checked by default and unchecking it will disable the Brace Highlighting feature.


posted @ Wed, 08 Sep 2010 23:23:16 +0000 by Darren Kosinski


Why Choose!?

In part inspired by some of the great and positive feedback we received on Hydra at Delphi Live late last month, we have started a new marketing campaign around the product, with the simple tag line of “Why Choose!?”. The premise is that while more and more Delphi developers are looking at .NET and trying [...]

posted @ Wed, 08 Sep 2010 15:17:45 +0000 by RemObjects Delphi Prism


TimeZone in XE

Since the inclusion of TTimeZone in Delphi XE’s RTL, I was trying to write a small introductory article into how to get started with the class but never got the time. Now, I got some free time on my hands, so here it goes: The new class provides support for: Converting date/time values representing local [...]

posted @ Wed, 08 Sep 2010 08:55:42 +0000 by Alexandru Ciobanu


Access to older versions included with Delphi XE, C++Builder XE, Delphi Prism XE and RAD Studio XE

One of the great things about Delphi XE, C++Builder XE, Delphi Prism XE, and RAD Studio XE, is that you now get access to older versions at no extra charge.

This is great for teams adding team members who need to work on apps built with multiple versions of the products so you get licenses for the older versions you need plus the latest version.

Which earlier versions do you get access to?
Delphi XE -> Delphi 2010, Delphi 2009, Delphi 2007, Delphi 7
C++Builder XE -> C++Builder 2010, C++Builder 2009, C++Builder 2007 and C++Builder 6
Delphi Prism XE -> Delphi Prism 2011, 2010 and 2009
RAD Studio XE -> all of the above

How does it work?

If you purchase individual named user licenses, 5-packs or 10-packs, just go to http://www.embarcadero.com/xe-earlier-versions after you register your XE product serial number. You can enter your registered XE serial number and get serial numbers and downloads for the older versions. Those licenses will be tied to your user account and cannot be given away or sold. If your XE license is an upgrade, you will not receive duplicate licenses for the older version(s) you upgrade from.
You must request your older version licenses within 180 days of your purchase of the XE product.

If you purchase Network Named ToolCloud or Network Concurrent ToolCloud licenses, the older version licenses for versions 2007-2011 will be included as part of your network license. Each network license count is a suite license that can be used to run one of the included versions at a time. You can also get Delphi 7 and C++Builder 6 licenses on request. The Delphi 7 and C++Builder 6 licenses are single named user serial numbers and aren't managed via your license server or ToolCloud.
Older versions are not included with Academic licenses.

Questions that have come up and answers....

The first time I tried to request my older version licenses via the web page, it didn't work. Is it fixed?
Yes. There as initially a problem with an error message showing for languages other than English. That has been fixed.

Can I give away or sell my older version licenses?
No. They are considered part of your XE license and are tied to your user account. They cannot be given away or sold.

I already had version 2010, upgraded to XE. I went to the page to request another 2010 license but it sends me the same 2010 serial number I already had. Why is that?
Your earlier 2010 license and the XE you upgrade to are considered one named user license that covers both versions. If you are in that situation and go to the web page and request a 2010 license as an XE user, you will just get a re-send of your existing 2010 serial number and not an additional 2010 serial number.

If I buy an Architect edition, why do I only get Enterprise editions of some of the older licenses?
Some of those earlier products are only available in Professional and Enterprise editions.

Why don't I get the old Delphi for .NET personality of RAD Studio 2007?
That is an old technology that was replaced by Delphi Prism and we don't want to encourage use of that old product.

Why can't I get version 2006 or the much older versions?
Version 2006 included some third party licensed code that we are no longer able to ship. Delphi 6 and earlier and C++Builder 5 and earlier were discontinued years ago and we don't have plans to bring them back.

Why can't I manage Delphi 7 and C++Builder 6 licenses via my license manager and ToolCloud?
Those versions used an earlier version of our licensing technology. We are looking at offering those older versions via InstantOn in a future version of the ToolCloud.

Why do I have to request the older serial numbers and downloads separately? Why don't you just send them all at once when I buy XE?
It could be a little confusing for some customers when they purchase RAD Studio XE and receive twelve different serial numbers and download links. We tried to keep it simple by just delivering the XE license and allowing them to request the other licenses as needed.

Why is there a limit of 180 days to request my earlier version licenses? 
The earlier version fulfillment page for purchasers of this XE version will stay available for 6 months after the date we stop selling this version. The limit isn't technically applied to each individual user's purchase date.

If you have any more questions on the included earlier version licenses, you can ask them by commenting on this blog post and I'll be happy to answer them.

posted @ Tue, 07 Sep 2010 11:50:00 +0000 by Tim


RAD Studio XE Code Editor Search Shortcuts

Now that RAD Studio XE has shipped, I have a chance to post about some of the features that I worked on. Most of my time has been spent working on some features for future versions that I cannot talk about yet. But I did make a few small improvements to the RAD Studio XE code editor that are worth highlighting. I’ll start with my favorite little feature: a couple of keyboard shortcuts for searching in the code editor. I find myself using these new shortcuts several times a day.

When I’m searching for something in the code editor, I often know that the instance I want to find is above my cursor position. In previous versions of RAD Studio, I would usually press Ctrl+Home to go to the top of the file, then begin searching, hitting F3 a bunch of times until I found what I was looking for. In RAD Studio 2010, I would sometimes use the mouse to click the up arrow on the search bar, but the muscle memory of pressing Ctrl+Home, Ctrl+F would usually kick in before I thought of grabbing the mouse.

In RAD Studio XE, there are now two new keyboard methods for initiating a search: Shift+Enter and Ctrl+Enter. To use them, first invoke search (Search/Find, or Ctrl+F, or the equivalent in your favorite keybinding) and type your search term. Then to start your search, you can press:

  • Enter to search downwards.
  • Shift+Enter to search upwards.
  • Ctrl+Enter to search from the beginning of the file.

These keystrokes work only for initiating the search. As in previous versions, to find the next instance of the search term, you use the repeat search keystroke (in the default keybinding, F3 to search again downwards or Shift+F3 to search again upwards). Note that these new shortcuts do not change the search direction or scope for future searches. They are one-time modifiers.

This isn’t a big feature, but it’s one that I find myself using all the time.

In my next post, I’ll point out a few other little editor changes in RAD Studio XE.


posted @ Tue, 07 Sep 2010 17:03:21 +0000 by Darren Kosinski


Brian Lindahl on VS2010 Integration

Talking with Brian Lindahl, a Senior Developer on Oxygene, about Visual Studio 2010 Integration with Oxygene and Delphi Prism; mobile application development on the iPhone, Android and Windows Phone 7; and the Mono, MonoDroid and MonoTouch frameworks.

posted @ Mon, 06 Sep 2010 11:25:06 +0000 by RemObjects Delphi Prism


Скорость компиляции в Delphi XE

Опубликованы trial-версии продуктов средств разработки новой линейки XE.

Есть основания утверждать, что в новой Delphi XE компиляция проектов происходит заметно быстрее, чем в предыдущей версии 2010.

Если вы уже скачали trial-версию Delphi XE и попробовали пересобрать уже существующий проект под нее, то было бы общественно-полезно запостить здесь результаты наблюдений.

Рекомендуется брать в качестве анализа актуальный проект 2010 без библиотек сторонних разработчиков, чтобы:

- минимизировать ваше время на портирование проекта;

- максимизировать степень чистоты эксперимента.

Уважаемые пользователи C++Builder также могут внести свой вклад в дело развития технологий в составе RAD Studio XE. Здесь гарантий повышения скорости компиляции нет, но нам важна общая оценка качества новой среды разработки.


posted @ Fri, 03 Sep 2010 07:49:17 +0000 by Vsevolod Leonov


Teste nosso servidor DataSnap XE instalado no Amazon Cloud

Funciona assim, instalamos InterBase e uma aplicação DataSnap Server no Amazon EC2 e disponibilizamos a aplicação DataSnap client desenvolvidade em Delphi.

Se você quer usar um cliente DataSnap e ver na prática como é rápido o DataSnap XE, faça o download da aplicação cliente desenvolvida em Delphi e navegue pelas opções disponíveis na aplicação. O servidor estará disponível durante as próximas 24 horas.

Aqui algumas orientações sobre a aplicação que irá lhe ajudar a entender o que acontece quando você executa alguns dos server methods:

Tab Server Methods

  • Button Get Server DateTime – retorna a data e hora a partir do servidor Amazon
  • Jobs available – lista os registros a partir de um ClientDataSet, você pode editar, deletar e inserir dados

Using ClientDataSet (Master-Detail)

  • ClientDataSet usando modelo Master-Detail (somente leitura)

Reading Data from DBXReader

  • Essa tab tem 3 botoões, o primeiro lista os departamentos, o segundo diz ao objeto no server que a próxima requisição deverá ser ordernada por ID, o próximo botão irá ordernar por NOME. Este objeto no servidor é singleton, ou seja, tem apenas uma instância, se quando você solicitar a lista de departamento e esta não vier ordenada pelo item que você solicitou é porque alguém fez uma solicitação ao server para ordenar por outro campo. Este é um exemplo simples mostrando como funciona a gerenciamento de objetos.

Using DBX framework to send TParams

  • Adiciona registros na tabela Department passando os dados como um objeto TParams

Object Transfer

  • Recebe objetos do servidor

Faça o download da aplicacão cliente para DataSnap  aqui, unzip, clique e execute.

Este é um pequeno exemplo que mostra alguma das funcionalidades do DataSnap, Anders :) foi responsável pelo processo de teste :) .

Posts relacionados


posted @ Thu, 02 Sep 2010 16:39:56 +0000 by Andreano Lanusse


Server Response from: BLOGS1