优雅的方式来区分Path或Entry键

sum*_*ame 0 regex delphi delphi-2010

我有一个应用程序加载CAD数据(自定义格式),从本地文件系统指定绘图的绝对路径或从数据库.

通过将图纸标识符作为参数的库函数来实现数据库访问.

标识符的格式类似ABC 01234T56-T,而我的路径是典型的Windows路径(例如x:\Data\cadfiles\cadfile001.bin).

我想编写一个包装器函数将一个String作为一个参数,它可以是一个路径或一个标识符,它调用适当的函数来加载我的数据.

像这样:

Function CadLoader(nameOrPath : String):TCadData;
Run Code Online (Sandbox Code Playgroud)

我的问题:我怎样才能优雅地决定我的字符串是一个idnetifier还是文件的路径?使用正则表达式?或者只搜索'\'和':',它们没有出现在标识符中?

Bha*_*rat 5

试试这个吧

Function CadLoader(nameOrPath : String):TCadData;
begin
  if FileExists(nameOrPath) then
    <Load from file>
  else
    <Load from database>
end;
Run Code Online (Sandbox Code Playgroud)